首页 文章

不能在流星中工作的光纤 - 错误:流星代码必须始终在光纤内运行

提问于
浏览
0

我在服务器端使用流星反应中的光纤 . 我创建了一个api(使用灵活的:resjus包的atmospherejs),但我在服务器的日志中收到错误

var response = {};  var url = //any server url  var Future = Npm.require( 'fibers/future' );   var future = new Future();  xhttp.onreadystatechange = function() {
     if (this.readyState == 4 && this.status == 200) {
         data = JSON.parse(xhttp.responseText);
         console.log(data.status," -- responseText cancel image preview job -- ", xhttp.responseText," jobId -- ",id)
         if(data.status == "success"){
             console.log('success')
             mongoCollection.update({_id:id},{
                 $set:{
                     status: "cancel"
                 }
                 },(err)={
                     if(err) {
                         console.log("error")
                         response.status = "error";
                         response.message = err;
                         future.return( response);
                     }
                     else{
                         response.status ="success";
                         future.return( response);
                     }
             })
         }else {
             console.log("not success")
             response.status = data.status;
             response.message = data.message;
             future.return( response);
         }
     }  };  xhttp.open("POST", url);  xhttp.setRequestHeader('Content-Type', 'application/json');  xhttp.send(JSON.stringify(json));

我收到以下错误:

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

1 回答

  • 0

    试试这个:

    //...
    xhttp.onreadystatechange = Meteor.bindEnvironment(function() {
      //your function code goes here...
    });
    //...
    

相关问题