1 prototypes define: #Suspension &parents: {Cloneable} &slots:
2 {#closure -> []. #value -> Nil}.
3 "A suspension is a simple object that holds a closure for future evaluation.
4 The force method returns its ultimate value transparently and immediately.
5 This differs from the more complex Promise setup for eventual-sends."
7 b@(Method traits) suspend
8 "Create a new suspension to evaluate the Method."
9 [Suspension clone `setting: #{#closure. #value} to: {b. Nil}].
11 s@(Suspension traits) hasEvaluated
12 "The closure is wiped away once evaluation is successful, so we test that."
15 s@(Suspension traits) force
16 "Depending on whether the Suspension has been evaluated, return the stored
17 result or evaluate the closure and update the state before returning that
24 result := s closure do.