Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created February 18, 2010 23:24
Show Gist options
  • Save anfedorov/308209 to your computer and use it in GitHub Desktop.
Save anfedorov/308209 to your computer and use it in GitHub Desktop.
>>> def delay(n):
... x = [None]*(n+1)
... i = 0
... while 1:
... x[i] = yield(x[i])
... i = (i + 1) % (n + 1)
...
>>> f = delay(3)
>>> f.next()
>>> f.send(1)
>>> f.send(2)
>>> f.send(3)
>>> f.send(4)
1
>>> f.send(5)
2
>>> f.send(6)
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment