草庐IT

promise2

全部标签

javascript - 如何将参数传递给promise函数

这似乎是一个愚蠢的问题,但我是这个主题的新手。我正在研究Nodejs的promise。我想将参数传递给一个promise函数。但是我想不通。someModule.someFunction.then(username,password,function(uid){/*stuff*/}函数类似于varsomeFunction=newPromise(username,password,function(resolve,reject){/*stuffusingusername,password*/if(/*everythingturnedoutfine*/){resolve("Stuffwor

javascript - 如何将参数传递给promise函数

这似乎是一个愚蠢的问题,但我是这个主题的新手。我正在研究Nodejs的promise。我想将参数传递给一个promise函数。但是我想不通。someModule.someFunction.then(username,password,function(uid){/*stuff*/}函数类似于varsomeFunction=newPromise(username,password,function(resolve,reject){/*stuffusingusername,password*/if(/*everythingturnedoutfine*/){resolve("Stuffwor

javascript - Promise.all().then() 解决?

使用Node4.x。当您有Promise.all(promises).then()解析数据并将其传递给下一个.then()的正确方法是什么??我想做这样的事情:Promise.all(promises).then(function(data){//Dosomethingwiththedatahere}).then(function(data){//Domorestuffhere});但我不确定如何将数据获取到第二个.then().我无法使用resolve(...)在第一个.then().我发现我可以做到这一点:returnPromise.all(promises).then(funct

javascript - Promise.all().then() 解决?

使用Node4.x。当您有Promise.all(promises).then()解析数据并将其传递给下一个.then()的正确方法是什么??我想做这样的事情:Promise.all(promises).then(function(data){//Dosomethingwiththedatahere}).then(function(data){//Domorestuffhere});但我不确定如何将数据获取到第二个.then().我无法使用resolve(...)在第一个.then().我发现我可以做到这一点:returnPromise.all(promises).then(funct

javascript - Node.js 中对 Promise 的原生支持

当前版本的Node.js是否对Promise提供原生支持?Node.js使用V8引擎。Chrome也使用了这个JavaScript引擎,Chrome32原生支持Promise。但我似乎无法获得在Node.js中(本地)工作的promise。我已经在Chrome32中尝试了以下代码,它可以工作。varpromise=newPromise(function(resolve,reject){//doathing,possiblyasync,then…if(1===1/*everythingturnedoutfine*/){resolve("Stuffworked!");}else{rejec

javascript - Node.js 中对 Promise 的原生支持

当前版本的Node.js是否对Promise提供原生支持?Node.js使用V8引擎。Chrome也使用了这个JavaScript引擎,Chrome32原生支持Promise。但我似乎无法获得在Node.js中(本地)工作的promise。我已经在Chrome32中尝试了以下代码,它可以工作。varpromise=newPromise(function(resolve,reject){//doathing,possiblyasync,then…if(1===1/*everythingturnedoutfine*/){resolve("Stuffworked!");}else{rejec

javascript - 如何在 Python 中编写一系列 Promise?

是否可以写出promise的序列?(或任务)仅使用Python3.6.1StandardLibrary?例如,JavaScript中的promise序列写成:constSLEEP_INTERVAL_IN_MILLISECONDS=200;constalpha=functionalpha(number){returnnewPromise(function(resolve,reject){constfulfill=function(){returnresolve(number+1);};returnsetTimeout(fulfill,SLEEP_INTERVAL_IN_MILLISECO

javascript - 如何在 Python 中编写一系列 Promise?

是否可以写出promise的序列?(或任务)仅使用Python3.6.1StandardLibrary?例如,JavaScript中的promise序列写成:constSLEEP_INTERVAL_IN_MILLISECONDS=200;constalpha=functionalpha(number){returnnewPromise(function(resolve,reject){constfulfill=function(){returnresolve(number+1);};returnsetTimeout(fulfill,SLEEP_INTERVAL_IN_MILLISECO

promise和async用法及区别(详解)

一、promisepromise的概念Promise是异步编程的一种解决方案,是一个构造函数,自身有all、reject、resolve方法,原型上有then、catch等方法。特点:对象的状态不受外界影响。Promise对象代表一个异步操作,有三种状态:pending(进行中)、fulfilled(已成功)和rejected(已失败)一旦状态改变,就不会再变,任何时候都可以得到这个结果。Promise对象的状态改变,只有两种可能:从pending变为fulfilled和从pending变为rejected。一句话总结:就是用来解决地域回调问题(地域回调--回调函数里面嵌套回调函数)promi

使用Promise执行长期任务

在我的angular2应用程序我有一种可能需要很长时间的方法,所以我正在使用promise异步执行。我希望计算在后台,因此GUI将继续照常工作,但似乎我的GUI等待计算完成。服务中的方法“func”-returnnewPromise((resolve,reject)=>{console.log("2");//somelongprocessindatabaseconsole.log("3");if(result!=null){resolve(result);}else{reject("Failure");}});而且我正在使用该方法中的这种方法-this.service.func().then(