我是 Reason 的新手,目前正在尝试将个人项目从 js 转换为 Reason。到目前为止,除了异步的东西之外,它一直很容易。我无法延迟递归地调用我的函数。我有一个getPrice
返回 int 承诺的函数
type getPrice = unit => Js.Promise.t(int)
我想做另一个功能checkPrice
,除非满足条件,否则它会无休止地通过给定的用户价格检查当前价格。
let rec checkPrice = (userPrice) =>
Js.Promise.(
getPrice()
|> then_(
(currentPrice) =>
if (currentPrice >= userPrice) {
resolve(currentPrice)
} else {
/* call this function with setTimeout */
checkPrice(userPrice)
}
)
);
但我得到类型不匹配说setTimeout
应该是单元类型