promise1.scm 475 B

12345678910111213141516171819
  1. (define sb (java.lang.StringBuffer))
  2. (define p1 (promise))
  3. (define p2 (promise))
  4. (define p3 (promise))
  5. (promise-set-alias! p3 p2)
  6. (future
  7. (begin
  8. (define pv (force p1))
  9. (sb:append (format "after force: ~s~%~!" pv))
  10. (promise-set-value! p2 (* 2 pv))
  11. pv))
  12. (sb:append (format "main thread~%~!"))
  13. (promise-set-value! p1 123)
  14. (sb:append (format "Done: ~s~%~!" (force p3)))
  15. (display (sb:toString))
  16. ;; Output: main thread
  17. ;; Output: after force: 123
  18. ;; Output: Done: 246