【发布时间】:2017-09-13 22:56:41
【问题描述】:
我目前正在尝试使用此链接 https://davidwalsh.name/javascript-polling(以及许多其他链接)向我的应用程序添加轮询。
我可以访问以下已经实现的 api:
client.get('url')
// returns Promise with result of getting result from url
// for the application I am working on,
// the URL returns json that looks like the following
// {status: DONE or IN PROGRESS, other values...}
// when status is DONE other values are what I will use in the application
client.post('url', {data: passAnyDataHere})
// sends a post request with result of sending data to url
// starts the specific job
我遇到的一个问题是,在尝试调整我上面链接到的 JavaScript 轮询代码时,当我发现状态为 DONE 时,我无法将结果返回到 Promise 之外. 有人可以给我一些提示吗?(轮询直到我找到一个特定的值,然后返回该值以供以后使用)
我举个例子
export default function someFunction() {
let a = client.get('/status');
a.then( dataResult =>
{
if (dataResult.status == "DONE") {
//** want to get other values in dataResult here
// and store it somewhere else for use later
}
});
// ***want to work with results here.
// need some way to get the status of what happened inside the .then(..) part
// eventually have to return success or failure and results to the frontend
// (this part is already done)
}
代码的基础是https://github.com/erikras/react-redux-universal-hot-example#server-side-data-fetching(使用React.js/Node.js/Redux/等)
感谢任何提示/建议/帮助。谢谢!
另外,我正在处理的应用程序不使用 JQuery。
【问题讨论】:
标签: javascript node.js asynchronous