Source.k 440 B

12345678910111213141516171819
  1. promise {
  2. import Source from Std
  3. let source = Source<Nil>(set_timeout(50))
  4. await value = create_promise << lambda(resolve, reject) {
  5. source -> subscribe -> .{ resolve(.x) }
  6. }
  7. assert value is Nil
  8. let source_sync = Source<Int>(observer {
  9. for i in [3,5,7] {
  10. push i
  11. }
  12. })
  13. var p = 1
  14. source_sync -> subscribe -> lambda(x) {
  15. reset p *= x
  16. }
  17. assert p == 3*5*7
  18. }