The Wayback Machine - https://web.archive.org/web/20210314155722/https://github.com/graphql/dataloader/pull/264
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support browsers who do not support setImmediate #264

Open
wants to merge 2 commits into
base: master
from

Conversation

@nanto
Copy link

@nanto nanto commented Mar 14, 2021

This pull request allows browsers who don't support setImmediate to fallback to setTimeout.

Fixes #249

@linux-foundation-easycla
Copy link

@linux-foundation-easycla linux-foundation-easycla bot commented Mar 14, 2021

CLA Signed

The committers are authorized under a signed CLA.

setImmediate || setTimeout;
typeof setImmediate === 'function' ?
setImmediate :
fn => { setTimeout(fn, 0); };

This comment has been minimized.

@nanto

nanto Mar 14, 2021
Author

At first I wrote as following but it caused error on test.

    typeof setImmediate === 'function' ? setImmediate : setTimeout;
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/index.js:401:12

Cannot return enqueuePostPromiseJob because TimeoutID [1] is incompatible with
undefined [2] in the return value.

     src/index.js
 [2] 398│ ): (() => void) => void {
     399│   var batchScheduleFn = options && options.batchScheduleFn;
     400│   if (batchScheduleFn === undefined) {
     401│     return enqueuePostPromiseJob;
     402│   }
     403│   if (typeof batchScheduleFn !== 'function') {
     404│     throw new TypeError(

     /tmp/flow/flowlib_20a9f9de/core.js
 [1] 819│ ): TimeoutID;
@@ -239,7 +239,9 @@ var enqueuePostPromiseJob =
process.nextTick(fn);
});
} :
setImmediate || setTimeout;
typeof setImmediate === 'function' ?
fn => { setImmediate(fn); } :

This comment has been minimized.

@nanto

nanto Mar 14, 2021
Author

IE 11 throws "Invalid calling object" error if the receiver of setImmediate is not a window.

var o = { m: setImmediate }; o.m(function () { console.log('ok'); });
// => "Invalid calling object" error in IE 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant