I'm trying to call createTableIfNotExists
in this npm package, and do so synchronously in Meteor, server-side.
https://www.npmjs.com/package/azure-storage
However, the callback signature is of type function(error, result, response)
instead of the traditional function(error,result)
.
1) Because of that, I cannot use Meteor.wrapAsync
and instead have to use Meteor.bindEnvironment
2) I call 'bindEnvironment' as below. Note the callback with 3 arguments. This works, but now I would like to extract the return value
, back to the original method (i.e. the original fiber).
Note that simply defining 'addResult' outside the createTableService
does not work because the callback inside bindEnvironment
runs asynchrounously relative to the outside code...i.e. demoFunction()
returns before the callback sets addResult
.
var demoFunction = function(){
var addResult = null;
var tableService = azure.createTableService(acctName, acctKey);
tableService.createTableIfNotExists(asTableName, Meteor.bindEnvironment(function(error,result,response){
if (error) {
throw new Meteor.Error(500, "table create error - " + asTableName + ": "+ error);
}
console.log(result);
if(result){
addResult = /*call to meteor method*/
return addResult;
}
}));
return addResult; //this is what I would like to do, but will always be null, as written.
}
How can I call createTableIfNotExists
and still return addResult
back to the function that called demoFunction()
?
Thanks!