Javascript has many asynchronous functions. Sometimes, we need to wait until the asynchronous function returns than go on. Following give an sample function for waitfor
waitfor = function(){
var preFns = arguments;
var thenFn = function(){
var postFns = arguments;
var count_down = preFns.length;
var done = function(){
count_down--;
if(count_down == 0 ){
_.each(postFns, function(postFn){ postFn();});
}
};
_.each(preFns, function(preFn){
preFn(done);
});
}
return {then: thenFn};
}
---------------------------------
waitfor(
function(done) { loadXXX.call(me, done);},
function(done) { loadYYY.call(me, done); }
).then(
function() {
setDefaultCriteria.call(me);
registerWatchForZZZ.call(me);
}
);
分享到:
相关推荐
waitFor ( function ( ) { return someCondition ; } , 2000 , 'an optional reject message' ) . then ( function ( ) { console . log ( 'condition is fulfilled.' ) ; } ) . catch ( function ( ) { console ...
本文实例讲述了JavaScript自定义等待wait函数用法。分享给大家供大家参考。具体分析如下: 下面是一个js自定义的wait函数,...//wait for 3 seconds sleep(3000); 希望本文所述对大家的javascript程序设计有所帮助。
安装$ npm install p-wait-for用法import pWaitFor from 'p-wait-for' ;import pathExists from 'path-exists' ;await pWaitFor ( ( ) => pathExists ( 'unicorn.png' ) ) ;console . log ( 'Yay! The file now ...
npm install -g wait-for-mongo 用法 作为命令行工具 wait-for-mongo <mongo> 或者 export MONGO_URL= export TIMEOUT= wait-for-mongo 作为 NodeJS 模块 var waitForMongo = require ( 'wait-for-mongo' ) ; ...
事件.js 一个超级棒的 JavaScript 事件处理程序库 ... // Wait for the DOM to load before adding our hover events Events.ready(function() { var elem = document.getElementById('myElement'); // Do something
// pend.wait will have to wait for this hold to finishpend . go ( function ( cb ) { console . log ( "this function is immediately executed" ) ; setTimeout ( function ( ) { console . log ( "calling cb...
等待它等待某个命名的异步活动完成,然后再调度要执行的任何依赖函数。...// Assume we are in an express routegetIndex = function ( req , res , next ) { // Start a queue for all requests that come in fo
等待元素这是一个用纯 javascript 编写的辅助函数,一旦找到元素就会调用回调函数。 本浏览器支持:IE8及以上(使用document.querySelectorAll)Chrome Firefox 如果浏览器支持,该函数会尝试使用 Mutation Observer...
for(i=0;i(wait/100);i++) { //将i*1000改为i*100查看最后的效果 window.setTimeout("doUpdate(" + i + ")",i*1000); } } function doUpdate(num) { if(num == (wait/100)) { cycle(); //三分钟前提醒...
这是Go的 for JavaScript的翻译,在广泛使用。 如果要同时运行多个异步任务并在所有结果返回时运行函数,请使用此功能。 (例如,如果您要发出多个Web请求或数据库查询,请一起使用)。 这比串行发出每个请求要好...
茉莉花集成 与 jasmine 的集成测试。 以为例。 在浏览器中使用此工具的好处: 能够独立运行测试。 设置断点。 能够查看加载的页面的实际内容。 比phantomjs更快的性能。... page.waitFor(function() {
等待它 用于创建有效的自动...用法 waitForIt.setup(function(data) { // Save data to server}, 5000);// Push some datawaitForIt.push({some: 'data'});// ... and againwaitForIt.push({more: 'new data'});测验
LABjs 是一个很小的 JavaScript 工具,用来根据需要加载 JavaScript 文件,通过使用该工具可以提升页面的性能,避免... // wait for all to load, then do something script1Func(); script2Func(); script3Func();
等待使用承诺等待条件的真相用法(直接作为全局) var condition = false;...promsie.waitFor(function() { return condition }).done(function() { doSomething()})节点var waitsfor = require('waitsfor')
不耐烦 一种将异步事物变成自己不耐烦的版本的工具 安装 npm installimpatient 用法 var impatient = require ( 'impatient' ) ; var sleep = require ( 'sleep...// impatient callback (wait for 1000ms but give up
安装 npm install wait-for-ip用法 var waitForIP = require ( 'wait-for-ip' ) ;waitForIP ( \\ , function ( ) {} ) ;执照麻省理工学院许可证 (MIT) 版权所有 (c) 2014 Bryan Hughes ( ) 特此授予任何人免费获得本...
The Spread Toolkit的Javascript绑定 用法 var spread = require ( "spread-for-node" ) ; //Connecting to a Spread daemon is pretty simple var mbox = spread . connect ( "localhost" , 4803 , "testuser" , 0...
* Fix conflict with plugin using Google Library Javascript for jQuery. Example : "Use Google Libraries" * Add an option for choose input text or textarea for old tags field * Add an option for min ...
// trigger wait for 1 second boo . wait ( ) ; boo.interval(fn,毫秒) 每隔ms用户处于非活动状态运行一个函数。 嘘.等待() 重置定时器以执行功能。 boo.wait超时 在运行任务之前等待超时。 默认值为1000
安装npm install --save spawn-wait-for用法var spawnWaitFor = require ( 'spawn-wait-for' ) ;spawnWaitFor ( 'fakeServer' , / server is running / ) . then ( function ( obj ) { obj = { process : Object , /...