Clojurescript-从本机模块正确调用诺言

问题描述 投票:2回答:1

我是Clojurescript的新手。我正在尝试在基于Java的react native模块中调用一个函数。所有本机模块都在react native中返回诺言,而我正在尝试使ClojureScript位正确,但是在编译期间从Node收到一条消息,内容为“ UnhandledPromiseRejectionWarning:未处理的诺言拒绝...”。我猜想Node认为从Clojurescript生成的JS没有'reject'子句。

我的代码如下:

(when platform/android?
     (try
       (->
         ((.-isAvailable RNTextDirection)) ;1st native module function
         (.then
           (fn [value]
             (when value
               (->
                 ((.-isRTL RNTextDirection) text)  ;2nd native module function
                 (.then (fn [value] ( (or value (right-to-left-text? text) (assoc :rtl? true))))
                 (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true))))))))
         (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true)))))
       (catch js/Object err ( (right-to-left-text? text) (assoc :rtl? true))))))

有人可以帮助我了解这里缺少什么吗?谢谢!

node.js react-native react-native-android clojurescript
1个回答
0
投票

我尚未使用CLJS的React Native,但似乎您(.catch ...)都承诺可能发生故障的链,这意味着警告是虚假的。与CLJS编译器不会产生所有函数调用相比,我更怀疑Node如何执行未处理拒绝检查。 CLJS运行时可能存在一个间接层,该层阻止Node意识到潜在的拒绝已得到处理。

© www.soinside.com 2019 - 2024. All rights reserved.