草庐IT

promises

全部标签

javascript - 如何使用 angular2 和 typescript 链接 3 个 Promise

我已经成功地链接了promise,但我发现我做这件事的方式足够复杂:我想知道是否有更优雅的方式来做到这一点。我使用Angular2、Typescript和signalR。我有一个服务getIntervention,它通过Id从服务器返回一个对象。在调用getIntervention之前,我想检查要连接到服务器的客户端,在连接到服务器之前,我想要加载SignalR脚本。所以我创建了第一个promisescriptLoadedPromise,它等待加载SignalR脚本。当scriptLoadedPromise被解析时,一个新的promiseconnectionPromise被创建,等待连

javascript - 为什么我要使用 Redux Promise 中间件而不是 Redux Promise?

我用过ReduxPromise,但似乎ReduxPromiseMiddleware具有更多功能,例如分派(dispatch)多个附加了“PENDING”或“FULFILLED”的操作。为什么我要用一个而不是另一个? 最佳答案 我个人更喜欢ReduxPromiseMiddleware作为中间件,因为它支持乐观更新;调度未决、已完成和已拒绝的操作;并与ReduxThunk配合得很好链接异步操作。例如,您可以在reducer中使用带有_PENDING和_FULFILLED的操作,并使用进度条等更新UI。

javascript - 为什么直接将 Promise.all 传递给 .then 函数会抛出错误?

我想直接将Promise.all传递给.then函数,例如:consttest=[Promise.resolve(),Promise.resolve(),Promise.resolve(),Promise.resolve()];Promise.resolve(test)//It'ssupposedtobeanAJAXcall.then(Promise.all)//Getanarrayofpromises.then(console.log('End');但是这段代码抛出错误Uncaught(inpromise)TypeError:Promise.allcalledonnon-object

javascript - 扩展 Javascript promise 并在构造函数中解决或拒绝它

我想用ES6语法扩展原生JavascriptPromise类,并且能够在子类构造函数中调用一些异步函数。根据异步函数结果,promise必须被拒绝或解决。然而,当then发生了两件奇怪的事情。函数被调用:子类构造函数执行两次“UncaughtTypeError:Promiseresolveorrejectfunctionisnotcallable”抛出错误classMyPromiseextendsPromise{constructor(name){super((resolve,reject)=>{setTimeout(()=>{resolve(1)},1000)})this.name=

javascript - 简单的 promise 然后实现

最近,有人向我展示了一段在全栈开发人员面试中被问到的代码。它涉及创建一个promise,候选人应该在其中实现,传递给它一个解析函数,然后链接2个。我尝试非常天真地实现Promise只是为了让代码工作。创建了一个接受解析器函数的构造函数,创建了一个接受回调并返回Promise的Then函数,并简单地调用解析器函数的回调。classMyPromise{constructor(resolver){this.resolver=resolver;}then(callback){constresult=newMyPromise(callback);this.resolver(callback);r

javascript - 使用 promise 配置多个功能

这是Setfirefoxprofilewithprotractor的后续行动话题。根据setFirefoxProfilehowto,可以使用特殊的"helper"jscode设置firefox配置文件使用firefox-profile和q动态制作编码的Firefox配置文件的库。这对我有用,直到我尝试使用多个浏览器并配置multiCapabilities:exports.config={seleniumAddress:'http://localhost:4444/wd/hub',multiCapabilities:[{browserName:'chrome',specs:['foote

javascript - 是否可以将 promise 包装在生成器中?

我正在尝试使用生成器创建一个promise-wrapper,以便我可以:varasyncResult=PromiseWrapper($.ajax(...));到目前为止,我一直在尝试:functionPromiseWrapper(promise){returnfunction*wrapper(promise){promise.then(function(result){yieldresult;},function(err){throwerr;});}(promise).next().value}但这失败了,因为不允许在法线内屈服。有什么解决方法吗?谢谢:Dps:我正在使用babel将代

javascript - 为什么 'new Promise(...)' 返回 'undefined' ?

似乎如果在用于创建promise的函数中未引用“resolve”函数,则该promise未定义。在下面的代码中,...varcount=0;varlimit=3;//varthePromise;functiontimeout(_count){thePromise.resolve(_count);}functionsendMessage(){returnnewPromise(function(resolve,reject){if(++count>limit){reject({'LimitExceeded':count});}else{//Withthislineinplace,there

javascript - Promise/A+ 规范第 2.2.4 条背后的意图是什么?

promise/a+规范的第2.2.4条说:onFulfilledoronRejectedmustnotbecalleduntiltheexecutioncontextstackcontainsonlyplatformcode.然后在注释中指出:Here“platformcode”meansengine,environment,andpromiseimplementationcode.Inpractice,thisrequirementensuresthatonFulfilledandonRejectedexecuteasynchronously,aftertheeventlooptu

javascript - 带有 iron-ajax 响应的 promise

我如何编写响应来自iron-ajax的Promise。this.data={get:function(sort,page,pageSize){returnnewPromise(function(resolve,reject){//Executeiron-ajax.//...//resolve(iron-ajax'sresponse);});}}}; 最佳答案 您正在寻找listItem.generateRequest(),因为它会返回iron-ajax附带的iron-request对象,而该对象又提供一个名为request.comp