I’m trying to wrap a function from a node package with wrapAsync.
filepicker = new Filepicker('API Key')
filepickerStatSync = Meteor.wrapAsync(filepicker.stat, filepicker)
result = filepickerStatSyncr(url);
console.log('after')
The stat function is below.
Everything seem to work fine… the request call responds with the correct result, the final callback is called, the whole thing executes synchronously / yields correctly as far as I can tell… but the sync call never returns and console.log(‘after’) is never hit.
Filepicker.prototype.stat = function(url, options, callback) {
callback = callback || function(){};
if(!options) {
options = {};
}
if(!url) {
callback(new Error('Error: no url given'));
return;
}
request({
method: 'GET',
url: url+'/metadata?',
form: {
size: options.size || true,
mimetype: options.mimetype || true,
filename: options.filename || true,
width: options.width || true,
height: options.height || true,
writeable: options.writeable || true,
md5: options.md5 || true,
path: options.path || true,
container: options.container || true,
security: options.security || {}
}
}, function(err, res, body) {
console.log('err = '+err);
console.log('res = '+res);
console.log('body = '+body);
if(err) {
callback(err);
return;
}
var returnJson;
if(typeof(body)==='string'){
try {
returnJson = JSON.parse(body);
} catch(e) {
callback(new Error('Unknown response'), null, body);
return;
}
} else {
console.log('returnJSON');
returnJson = body;
}
console.log('callbacked');
callback(null, returnJson);
});
};