Skip to content

Instantly share code, notes, and snippets.

@jimblandy
Last active December 11, 2015 04:18
Show Gist options
  • Save jimblandy/4543764 to your computer and use it in GitHub Desktop.
Save jimblandy/4543764 to your computer and use it in GitHub Desktop.
Operation callback testing API
triggerOperationCallback([delay])
Trigger an operation callback.
If 'delay' is given, it must be a positive integer; wait that many operation
callback opportunities to trigger the callback. (Note that delay counts only
work when we are running a body function from 'withOperationCallback'.)
withOperationCallback(body, [callback])
Call the function 'body', establishing the function 'callback' as the
operation callback while 'body' runs. Once 'body' completes, restore the
runtime's original operation callback. Return whatever value or throw whatever
exception 'body' did.
If 'callback' returns normally, resume execution in 'body'. If 'callback'
returns a positive integer, trigger another operation callback after that many
operation callback opportunities have passed. (Thus, if 'callback' returns
zero, trigger another operation callback at the next opportunity.)
If 'callback' throws or is terminated, then that is propagated to 'body'.
While 'callback' runs, we temporarily restore the original operation callback.
When we resume execution in 'body', 'callback' is reinstated.
If 'callback' is omitted, then let triggering an operation callback simply
terminate the execution of 'body' (as if by the 'terminate' function).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment