Unsubscribe.k 454 B

123456789101112131415161718192021222324
  1. promise {
  2. let clock = observer {
  3. var enabled = true
  4. promise {
  5. while enabled {
  6. await postpone(50)
  7. push Nil
  8. }
  9. }
  10. return lambda {
  11. reset enabled = false
  12. }
  13. }
  14. var n = 0
  15. let unsub = clock -> subscribe -> lambda {
  16. reset n += 1
  17. }
  18. await postpone(180)
  19. unsub()
  20. assert n == 3
  21. await postpone(120)
  22. assert n == 3
  23. }