我是 Clojurescript 新手。我正在尝试调用基于 java 的 React Native 模块中的函数。所有 native 模块都在 React Native 中返回 Promise,我试图让 ClojureScript 位正确,但在编译期间我从 Node 收到一条消息“UnhandledPromiseRejectionWarning:未处理的 Promise 拒绝...”。我猜 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))))))
任何人都可以帮助我理解这里缺少什么吗?谢谢!
最佳答案
我还没有使用过 CLJS 的 React Native,但看起来你 (.catch ...)
两个 promise 链都可能失败,这意味着警告是虚假的。我更怀疑 Node 如何执行未处理拒绝的检查,而不是 CLJS 编译器不生成所有函数调用。 CLJS 运行时可能有一个间接层,阻止 Node 意识到潜在的拒绝已被处理。
关于node.js - Clojurescript - 正确调用 native 模块的 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56620798/