We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 50a61ac + 1e0a36c commit a56478aCopy full SHA for a56478a
src/index.js
@@ -4,7 +4,11 @@
4
*/
5
let callbacks = [];
6
7
-const channel = new MessageChannel();
+let channel = new MessageChannel();
8
+
9
+let postMessage = (function() {
10
+ this.postMessage(undefined);
11
+}).bind(channel.port2);
12
13
// Flush the callback queue when a message is posted to the message channel
14
channel.port1.onmessage = () => {
@@ -22,9 +26,8 @@ channel.port1.onmessage = () => {
22
26
}
23
27
};
24
28
25
-function postMessage() {
- channel.port2.postMessage(undefined);
-}
29
+// If the onmessage handler closes over the MessageChannel, the MessageChannel never gets GC'd:
30
+channel = null;
31
32
/**
33
* Invoke the given callback after the browser renders the next frame
0 commit comments