Created
October 5, 2019 00:15
-
-
Save steida/7ce3a9d965647bf807b7d2aa0ea88d9e to your computer and use it in GitHub Desktop.
Revisions
-
steida created this gist
Oct 5, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ // Draft uses YuzuJS/setImmediate polyfill, which can be reduced to this code. // But it seems request requestAnimationFrame is good enough. // TODO: Will it work with queue fix? // // https://github.com/google/closure-library/blob/master/closure/goog/async/nexttick.js#L209 const setImmediate = (() => { const channel = new MessageChannel(); let head: any = {}; let tail = head; channel.port1.onmessage = () => { if (head.next !== undefined) { head = head.next; const { callback } = head; head.callback = null; callback(); } }; return (callback: () => void) => { tail.next = { callback }; tail = tail.next; channel.port2.postMessage(0); }; })();