Status.k 867 B

1234567891011121314151617181920212223242526272829303132
  1. promise {
  2. enum Status { Running, Error, Complete }
  3. let make_status = lambda (s: Status) {
  4. return observer {
  5. switch match s {
  6. Status.Running {
  7. push 1
  8. }
  9. Status.Error {
  10. push custom_error('Oops!')
  11. }
  12. Status.Complete {
  13. push Complete
  14. }
  15. }
  16. }
  17. }
  18. let sub = lambda (s: Status) {
  19. return create_promise << lambda (resolve, _) {
  20. make_status(s) -> subscribe -> Subscriber {
  21. next: .{ _ --> resolve(Status.Running) },
  22. error: .{ _ --> resolve(Status.Error) },
  23. complete: .{ resolve(Status.Complete) }
  24. }
  25. }
  26. }
  27. for S in Status {
  28. await t = sub(S)
  29. assert t is S
  30. }
  31. }