Getting back callback parameters when using Meteor.wrapAsync()

I’m trying to implement a Vimeo API and after some thought, the only way I could do this while returning appropriate responses to client was if I did it synchronously (in conjunction with a try/catch block).

Anyway, this is the Vimeo function I converted to sync via Meteor.wrapAsync:

lib.streamingUpload("/path/to/file", (err, body, status_code, headers) => {});

Of course, this is how it turns out with the wrapAsync:

const upload = Meteor.wrapAsync(lib.streamingUpload, lib);

Now, when I console log the upload above, the only parameter it returns is the body. For purposes of storing the upload URL, I need to have access to the headers parameter. How could I do this with Meteor.wrapAsync()?

You can’t do it directly with wrapAsync - that’s onle able to deal with functions with a (error, result) signature.

However, you could wrap streamingUpload to have an object {body, statusCode, headers} as the second parameter and then wrapAsync the wrapped streamingUpload.

Hope that makes sense!

You could do something similar with Promises. In fact if the Vimeo API has a Promise interface, I’d use that directly.

Unfortunately, promises don’t work with Vimeo’s library.

I’ll try wrapping the functions instead and see how that works.