【发布时间】:2017-11-23 17:23:01
【问题描述】:
我正在查看 A First Reason React app for Javascript developers 上的 Reason 示例
而且我看到他在使用bs-fetch时正在调用Js.Promise.resolve:
RepoData.fetchRepos()
|> Js.Promise.then_(repoData => {
handleReposLoaded(repoData);
Js.Promise.resolve();
})
|> ignore;
我也在 BuckleScript 代码中看到过类似的代码。比如Bucklescript Cookbook:
Js.Promise.(
Fetch.fetch "https://api.github.com/users/reasonml-community/repos"
|> then_ Fetch.Response.text
|> then_ (fun text ->
text
|> names
|> Array.iter Js.log
|> resolve)
|> ignore
在 JS 中,我们通常在创建新的 Promise 时调用 resolve,而不是在使用返回 Promise 的函数时。那么为什么在上述情况下我们需要调用resolve呢?
【问题讨论】:
标签: promise reason bucklescript