草庐IT

dart-async

全部标签

javascript - Node.JS async.parallel 不会等到所有任务都完成

我正在使用aync.parallel并行运行两个函数。这些函数请求RSS提要。然后RSS提要被解析并添加到我的网页。但由于某些原因async.parallel运行回调方法时没有等到两个函数完成Thedocumentationsays:Oncethetaskshavecompleted,theresultsarepassedtothefinalcallbackasanarray.我的代码。require('async').parallel([function(callback){fetchRss(res,bbcOpts);//Needstimetorequestandparsecallb

javascript - 将 async/await 与 babel 一起使用 - 要求 ("babel-polyfill") 行不在构建文件的顶部

我正在尝试将ES2017async/await语法与Babel结合使用。在package.json中,我有"babel":{"plugins":["babel-plugin-transform-async-to-generator"],"presets":["es2015"]}//..."devDependencies":{"babel-cli":"^6.14.0","babel-plugin-transform-async-to-generator":"^6.8.0","babel-polyfill":"^6.13.0","babel-preset-es2015":"^6.14.0"

javascript - Fabric.js 子类化 fabric.Group - 错误 : "Cannot read property ' async' of undefined"when load from JSON

有以下问题:尝试继承fabric.Group:varCustomGroup=fabric.util.createClass(fabric.Group,{type:'customGroup',initialize:function(objects,options){options||(options={});this.callSuper('initialize',objects,options);this.set('customAttribute',options.customAttribute||'undefinedCustomAttribute');},toObject:functi

javascript - 如何在 Node JS FS 模块中使用 Typescript Async/await with promise

如何在nodejsFS模块中使用Typescriptasync/await函数并返回typescript默认promise,并在promise解决后调用其他函数。代码如下:if(value){tempValue=value;fs.writeFile(FILE_TOKEN,value,WriteTokenFileResult);}functionWriteTokenFileResult(err:any,data:any){if(err){console.log(err);returnfalse;}TOKEN=tempValue;ReadGist();//otherFSreadFileca

javascript - 使用 async/await 提交/回滚 knex 事务

我正在试驾ES7async/awaitproposal使用thismodule模仿它。我正在尝试制作knex.js作为起点,交易与它们配合得很好。示例代码:asyncfunctiontransaction(){returnnewPromise(function(resolve,reject){knex.transaction(function(err,result){if(err){reject(err);}else{resolve(result);}});});}//Starttransactionfromthiscallinsert:async(function(db,data){

javascript - 未处理的 promise 拒绝警告 : This error originated either by throwing inside of an async function without a catch block

我的Node-Express应用出现以下错误UnhandledPromiseRejectionWarning:Unhandledpromiserejection.Thiserrororiginatedeitherbythrowinginsideofanasyncfunctionwithoutacatchblock,orbyrejectingapromisewhichwasnothandledwith.catch().(rejectionid:4)至少可以说,我创建了一个看起来像这样的辅助函数constgetEmails=(userID,targettedEndpoint,headerA

javascript - 前端 : underscore. js 或 async.js 通过 browserify?

因此,如果您是后端node.js开发人员,您就会知道名为async的很棒的库。.如果您是前端开发人员,您会知道名为underscore的很棒的库。.现在的情况是,这两个库在某种程度上倾向于提供相似的功能。所以问题是,使用browserify在前端使用异步是否有意义?? 最佳答案 Underscore是一个实用程序库,它提供了一些有用的函数,例如each、map和reduce。但是,所有这些都是同步工作的。例如varresults=_.map([1,2,3],function(value,index,list){returnvalue

javascript - 我可以在 AngularJS 中使用 Async.js 库吗?

我必须使用imgID的变体多次调用api:/1/dir/{imgID}(平均50次)。在node.js中我可以使用Async.js图书馆。我可以在Angular端使用这个库吗?如果是,请给我一些想法,如果不是,请给我一些替代想法,以便我可以在AngularJS中使用它? 最佳答案 是的,你可以。基本上,您需要使用$q.all(promises);,它可以将多个promise组合成一个promise,当所有输入promises都被解析时,该promise被解析。例子:http://www.bennadel.com/blog/2772-

javascript - 在 "Actions must be plain objects. Use custom middleware for async actions."中使用 Jest 模拟结果

我有几个Redux-Thunk风格的函数,可以在一个文件中分派(dispatch)其他操作。其中一个Action将另一个作为其逻辑的一部分进行分派(dispatch)。它看起来类似于:exportconstfunctionToMock=()=>async(dispatch)=>{awaitdispatch({type:'abasicaction'});};exportconstfunctionToTest=()=>async(dispatch)=>{dispatch(functionToMock());};在我实际遇到的情况下,这些函数都涉及更多,并且每个都分派(dispatch)多个

javascript - 服务人员 : async await in combination with waituntil is not working properly

在使用async/await语法时,我正在为serviceworker中的promises而苦苦挣扎。以下情况:我收到推送通知,想处理点击事件。如果我将“旧”语法与then和catch一起使用,我可以遍历客户端列表并对其执行一些操作。如果我对async/await使用我喜欢的方式,它不会做任何事情。self.addEventListener("notificationclick",event=>{//isworkingevent.waitUntil(self.clients.matchAll().then(clientList=>{console.log(clientList);}))