Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Created May 8, 2011 16:15
Show Gist options
  • Save DmitrySoshnikov/961469 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/961469 to your computer and use it in GitHub Desktop.
$coroutine = (func) -> ->
gen = func(arguments...)
gen.next()
gen
grep = $coroutine (pattern) ->
console.log "Looking for #{pattern}"
while true
line = yield
if line.indexOf pattern != -1
console.log "Found #{pattern} in #{line}"
on
g = grep("Coffee")
g.send("JavaScript")
g.send("CoffeeScript")
@satyr
Copy link

satyr commented May 8, 2011

Try: line = yield``

@DmitrySoshnikov
Copy link
Author

Yep, thanks, actually it's OK, just JS 1.7 was disabled. Coffee normally compiles yield as an identifier. Though, if to reserve it as the keyword, it should fail to compile when yield is used improperly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment