2017-04-21 49 views
1

我有這樣的錯誤,當我試圖使用睡眠循環流星光纖中運行與setTimeout的

Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

我的代碼:

fs.readdir(directory, (err, files) => { 
     if (err) { 
     console.log("error get file"); 
     } 

     if(files.length > 0) { 
     for (var i = 0; i <files.length; i++) { 
      Fiber(function() 
      { 
      setTimeout(function() 
      { 
       Meteor.call('mymethodfile', files[i]); 
      }, 1000); 
      }).run(); 
     } 
     } 
    }); 

在同一個文件

Meteor.methods({ 
    'mymethodfile':function(arch) 
    { 
     var file=arch; 
     console.log(file); 
     getdata(file); 
    } 
}) 

請幫我

回答

相關問題