Skip to content

Instantly share code, notes, and snippets.

@kuraga
Created January 18, 2016 19:48
Show Gist options
  • Save kuraga/b0aa3d66fc0620f03b11 to your computer and use it in GitHub Desktop.
Save kuraga/b0aa3d66fc0620f03b11 to your computer and use it in GitHub Desktop.
Test concurrent call of the same function
var longActionCalled = 0,
firstlongActionCallFinished = false,
secondRedrawRequested = false;
function longAction() {
longActionCalled++;
switch (longActionCalled) {
case 1:
render(); // rafs longAction call
// I don't know if setImmedite can help here. But now it's not realized.
// setTimeout: "code cannot be executed until the thread that called setTimeout() has terminated."
setImmediteReally(function () {
secondRedrawRequested = true;
});
while (!secondRedrawRequested);
firstlongActionCallFinished = true;
break;
case 2:
assert(firstlongActionCallFinished);
done();
break;
}
}
render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment