T
T
tangro2012-03-22 18:30:18
JavaScript
tangro, 2012-03-22 18:30:18

How to make an asynchronous wrapper for a synchronous library?

There is someone else's Javascript library. She is synchronous. That is, by calling its a() function, you need to wait (sometimes for a long time) for its return. I would like to make an asynchronous cropper over this library. Those. so that I call the wrapper.a (func) method, which immediately returns, somewhere in parallel by running the a () function. Then, when a() is executed, my func handler will be called.
What is the easiest/correct way to do this? So far, only timers come to mind, but I'm generally new to Javascript - maybe there is something smarter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yurtaev, 2012-03-22
@yurtaev

setTimeout(function () {
    var data = a();
    callback(a);
}, 0);

You can decorate the function to call something like thisa(args, callback)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question