How can we use promise on top of Duktape?
My Scenario: Migrating a client side javascript code that loads well on web browsers to Duktape. I am using Dukluv (binding with Duktape and libuv library) binary to run the JavaScript. However my javascript depends on BlueBird library.
When I try to execute I get an error:
no async scheduler available
The problem is in bluebird's schedule.js line 33. Code is below for reference:
else if ((typeof MutationObserver !== "undefined" &&
(_MutationObserver = MutationObserver)) ||
(typeof WebKitMutationObserver !== "undefined" &&
(_MutationObserver = WebKitMutationObserver))) {
schedule = (function() {
var div = document.createElement("div");
var queuedFn = void 0;
var observer = new _MutationObserver(
function Promise$_Scheduler() {
var fn = queuedFn;
queuedFn = void 0;
fn();
}
);
observer.observe(div, {
attributes: true
});
return function Promise$_Scheduler(fn) {
queuedFn = fn;
div.classList.toggle("foo");
};
})();
}
There is no webkitmutationobserver nor document object as I am running my script on Dukluv without any browser.
I also tried to use Q library, even there I get an error setTimeout not defined
. Please suggest me a solution, if possible with some snippet of code. Thanks