1 defer = (g) -> 2 deferred = [] 3 go = (i) -> 4 {value,done} = do i.next 5 unless done 6 deferred.push value 7 go i 8 exit = -> 9 do f for f in deferred 10 process.removeListener 'exit', exit 11 process.on 'exit', exit 12 try go do g 13 catch then do exit 14 15 foo = (type) -> defer -> 16 console.log "#{type} 1" 17 yield -> console.log "#{type} deferred 1!" 18 yield -> console.lo