0
我在流星中使用光纖+在服務器端作出反應。我已經創建了一個API(使用靈活:atmospherejs的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.]