草庐IT

promised-mongo

全部标签

javascript - mocha js 断言在使用 promise 时挂起?

"usestrict";letassert=require("assert");describe("Promisetest",function(){it('shouldpass',function(done){vara={};varb={};a.key=124;b.key=567;letp=newPromise(function(resolve,reject){setTimeout(function(){resolve();},100)});p.then(functionsuccess(){console.log("success---->",a,b);assert.deepEqual

javascript - 如何在 AngularJS 中访问在 promise 中声明的变量

我是AngularJS的新手,我需要访问在Javascript中分配的变量this.reqData=this.profileService.getData();varresp1=angular.fromJson(this.reqData);this.data1;varthat=this;resp1.$promise.then(function(data){that.data1=data.resource.resource;}).catch(function(error){console.log(error);});console.log(this.data1);变量data1可以从HT

javascript - 使用 Promises 通过 Bluebird promises 库在另一个函数中调用函数

我有3个NodeJs函数。我想在这里做的是,我想调用normalizeFilePath并获取规范化路径,然后检查该文件是否存在normalizedFilePath最后这些,如果文件不存在则创建一个文件。这是使用promises(Bluebird)的第一天,我是NodeJS和JavaScript的新手。下面的代码结构越来越复杂。当然,这根本不是一个好主意。varcreateProjectFolder=function(projectName){};varcheckFileExistance=function(filePath){returnnewpromise(function(reso

javascript - 在 promise 中使用 then()

我在下面的代码块中使用了promise,2firstthen()我没有返回任何值,所以我想知道第一个then()中的函数是在下一个then()中的函数之前调用的。我在Angular2中使用typescript。谢谢:DPromise.resolve().then(()=>{this.getListStatus();}).then(()=>{returnthis._laundryServiceOrderService.findAll(true,offset,this.itemsPerPage,filterQuery)}).then((response)=>{this.orders=res

JavaScript ES6 - promise 解决和事件之间可能存在竞争条件?

是否可以在promise解析和promise等待返回之间执行用户代码?functiona(){returnnewPromise(resolve=>{setTimeout(()=>{//Betweenhere...resolve()},1000))}}asyncfunctionb(){awaita()//...andhere?}规范是否强制立即调用Promise回调?我想知道2点之间的虚拟机是否可以处理一个事件,这可能会导致副作用。 最佳答案 不,它不强制立即调用。Thespec在解决一个promise时会经历许多步骤,其中之一是:P

javascript - 为什么 Promise 没有 get() 函数?

如果您知道Promise已经被解决,为什么不能直接调用get()并接收值呢?与将then(..)与回调函数一起使用相反。所以不要这样做:promise.then(function(value){//dosomethingwithvalue});我希望能够做的更简单:varvalue=promise.get();Java为它的CompletableFuture提供了这个我看不出为什么JavaScript不能提供相同的功能。 最佳答案 Java的get方法“如有必要,等待此future完成”,即它会阻塞当前线程。我们绝对不想在只有一个“

javascript - Promise 不会等待 for 循环完成

我有一个异步代码,我想在我的一个Nodejs脚本中同步运行,但这不会等待代码块完成并解析空对象-newPromise((resolve,reject)=>{if(object.email!==undefined){for(leti=0;i{console.log('>>isEmailUnsubscribedresultinsendemailnotification:'+result)if(!result){emailObjects.push(emailObject.EmailID)}})}}console.log('emailObjects')console.log(emailObje

javascript - 有没有一种好的方法可以缩短 Javascript 的 promise ?

我对promises/Deferreds有点陌生。对于成功和错误的情况,是否有一个好的模式来处理可能想要缩短promise链的情况?在错误情况下,我知道你可以将一个.then(null,function(error){})链接到最后并从之前的任何一个then中捕获错误,但是如果你想以更自定义的方式处理错误并终止?您是否会在较早的错误处理程序中指定错误的“类型”并通过新的promise返回它,以在最终的错误处理程序中处理或跳过?如果您想在链中更早地终止(仅有条件地触发任何稍后的then)的成功案例呢? 最佳答案 通常,promise链

javascript - 解决后未将 promise 值放入模板

我对javascript和promises还很陌生,所以我可能无法理解所有的基本概念,但我正在尝试。我的模型中有一个检查友谊状态的函数:friendShipStatus:function(){varself=this;returnEmber.RSVP.all([this.container.lookup('user:current'),this.get('myFriends'),this.get('friendsWithMe'),this.get('friends')]).then(function(result){varuser=result[0],myFriends=result[

javascript - jQuery promise 是否符合 Promises/A+

我已阅读thisarticle这是基于著名的DomenicDenicola'sarticle.第一个说:TheproblemwithjQuery’simplementation(upuntilversion1.9)isthatitdoesn’trespectthesecondpartofthespecification,“Thisfunctionshouldreturnanewpromise…”,thatis“then”doesn’treturnanewpromiseobjectwhenexecutingoneofthehandlers(eitherthefullfillment,th