Skip to content

Commit

Permalink
value async fail safe
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Nov 17, 2024
1 parent 7107a8c commit c035fdb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/hyperx/value.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@ proc wakeupSoon(f: Future[void]) {.raises: [].} =
callSoon wakeup

proc put*[T](vala: ValueAsync[T], val: T) {.async.} =
if vala.isClosed:
raise newValueAsyncClosedError()
check not vala.isClosed, newValueAsyncClosedError()
while vala.val != nil:
check not vala.isClosed, newValueAsyncClosedError()
vala.putWaiter.clean()
await vala.putWaiter.fut
vala.val = val
wakeupSoon vala.getWaiter.fut
while vala.val != nil:
check not vala.isClosed, newValueAsyncClosedError()
vala.putWaiter.clean()
await vala.putWaiter.fut

proc get*[T](vala: ValueAsync[T]): Future[T] {.async.} =
if vala.isClosed:
raise newValueAsyncClosedError()
check not vala.isClosed, newValueAsyncClosedError()
while vala.val == nil:
check not vala.isClosed, newValueAsyncClosedError()
vala.getWaiter.clean()
await vala.getWaiter.fut
result = vala.val
Expand Down

0 comments on commit c035fdb

Please sign in to comment.