2017-04-21 50 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); 
    } 
}) 

请帮我

回答

相关问题