Created
June 25, 2013 00:51
-
-
Save davidchambers/5855045 to your computer and use it in GitHub Desktop.
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 characters
# Takes a box (an array) and a function, f, which takes a continuation. | |
# A sentinel is placed in the box, then f is invoked. When f calls its | |
# continuation, c, the box is inspected. Only if the sentinel is still | |
# in the box will c in turn call its continuation. | |
# | |
# If several asynchronous requests are made in quick succession, the | |
# responses may not be received in the order in which they were sent. | |
# This function makes it possible to define a function to be invoked | |
# *unless the request has been superseded by the time it completes*. | |
skip_continuation_if_superseded = (box, f) -> | |
box[0] = sentinel = {} | |
f (continuation) -> continuation() if box[0] is sentinel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment