Fibers not working in meteor react


#1

I am using fibers in meteor + react on server side. I have created a api (using nimble:restivus package of atmoshpherejs) but I am getting error on server’s log

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));

I am getting following error:-

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


#2

Why not use the HTTP package, which works with fibers out of the box? http://docs.meteor.com/api/http.html