coroutine.lua 427 B

1234567891011121314151617181920
  1. local Rx = require 'rx'
  2. local scheduler = Rx.CooperativeScheduler.create()
  3. -- Cheer someone on using functional reactive programming
  4. local observable = Rx.Observable.fromCoroutine(function()
  5. for i = 2, 8, 2 do
  6. coroutine.yield(i)
  7. end
  8. return 'who do we appreciate'
  9. end, scheduler)
  10. observable
  11. :map(function(value) return value .. '!' end)
  12. :subscribe(print)
  13. repeat
  14. scheduler:update()
  15. until scheduler:isEmpty()