File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -88,13 +88,20 @@ pub fun try-await( p : promise<a> ) : <async,ndet> maybe<a>
8888// Resolve a promise to `value`. Raises an exception if the promise was already resolved.
8989pub fun resolve ( p : promise < a> , value : a ) : asyncx ()
9090 async-io
91- val r = p. state
92- match ! r
93- Awaiting (listeners) ->
94- r := Resolved (value)
95- listeners. foreach fn (cbx) // todo: through set-immediate?
96- cbx(value) // set-immediate1( cbx, value )
97- _ -> throw("Promise was already resolved " )
91+ if ! try-resolve-io(p, value) then
92+ throw("Promise was already resolved " )
93+
94+ // Resolve a promise to `value`. Returns False if the promise was already resolved.
95+ // TODO: make this io-noexn
96+ pub fun try-resolve-io ( p : promise < a> , value : a ) : io bool
97+ val r = p. state
98+ match ! r
99+ Awaiting (listeners) ->
100+ r := Resolved (value)
101+ listeners. foreach fn (cbx) // todo: through set-immediate?
102+ cbx(value) // set-immediate1( cbx, value )
103+ True
104+ _ -> False
98105
99106// ----------------------------------------------------------------------------
100107// Channels
You can’t perform that action at this time.
0 commit comments