2016-12-20 5 views
0
var blah = require('wait.for'); 
var wait = require('wait.for/parallel-tests'); 

function testFunction(){ 
    console.log('fiber start'); 
    wait.miliseconds(10*1000); 
    console.log('fiber end'); 
}; 

console.log('app start'); 
blah.launchFiber(testFunction); 
console.log('after launch'); 

나는 다음과 같은 출력 내가 잘못 뭐하는 거지wait.for를 사용하는 방법?

app start
fiber start
Z:\nodeplayground\node_modules\wait.for\waitfor.js:15
Fiber(function(){ fn.apply(null, newargs)}).run(); //launch new fiber,
call the fn with the args, this=null (strict)
^
TypeError: wait.miliseconds is not a function
at testFunction (Z:\nodeplayground\index.js:8:10)
at Z:\nodeplayground\node_modules\wait.for\waitfor.js:15:31

를 얻을 수 위의 코드를 실행하려고?

내가 달성하고자하는 주요 기능은 다음과

function testFunction2(){ 
    function Innerfunction(){ 
     setTimeout(function(){ 
     console.log("hello"); 
     },5000); 
     console.log("After setTimeout") 
    } 
} 

내가 위의 코드를 5 초 인쇄 "안녕하세요" 기다려야 할 것입니다 및 "에서는 setTimeout 후"그 후.

답변

0

모듈에서 내 보낸 milliseconds 메서드를 가져 오려고합니다.

기본 파일에 wait.milliseconds 기능을 선언하거나 재사용을 위해 모듈로 포장해야합니다.

var wait = require('wait.for'); 

wait.timeout_callback = function(ms,callback){ 
    setTimeout(callback,ms); //call callback(null,null) in ms miliseconds 
} 

wait.miliseconds = function(ms){ 
    wait.for(wait.timeout_callback,ms); 
}  

function testFunction(){ 
    console.log('fiber start'); 
    wait.miliseconds(10*1000); 
    console.log('fiber end'); 
}; 

console.log('app start'); 
wait.launchFiber(testFunction); 
console.log('after launch');