fibers not working in meteor react - Error: Meteor code must always run within a Fiber

fibers not working in meteor react - Error: Meteor code must always run within a Fiber

我在流星中使用光纤 + 在服务器端做出反应。我创建了一个 api(使用 atmospherejs 的 nimble:restivus 包),但我在服务器日志中收到错误消息

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.]

试试这个:

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