Skip to content

Commit

Permalink
Fixed a bug in the MessageChannel hack for nextTick instead of setTim…
Browse files Browse the repository at this point in the history
…eout.
  • Loading branch information
kriskowal committed Jul 14, 2011
1 parent 607e2b9 commit 8834723
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion q.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ try {
// modern browsers
// http://www.nonblocking.io/2011/06/windownexttick.html
var channel = new MessageChannel();
// singly-linked list of tasks
var head = {}, tail = head;
channel.port1.onmessage = function () {
var next = head.next;
var task = next.task;
head = next;
task();
};
enqueue = function (task) {
channel.port1.onmessage = task;
tail = tail.next = {task: task};
channel.port2.postMessage();
};
} else {
Expand Down

0 comments on commit 8834723

Please sign in to comment.