@@ -30,30 +30,52 @@ foreign import data AVar ∷ Type → Type
3030
3131foreign import data AVAR ∷ Effect
3232
33+ -- | Creates a fresh AVar.
3334foreign import makeEmptyVar ∷ ∀ eff a . AVarEff eff (AVar a )
3435
36+ -- | Creates a fresh AVar with an initial value.
3537foreign import makeVar ∷ ∀ eff a . a → AVarEff eff (AVar a )
3638
39+ -- | Synchronously checks whether an AVar currently has a value.
3740foreign import isEmptyVar ∷ ∀ eff a . AVar a → AVarEff eff Boolean
3841
42+ -- | Kills the AVar with an exception. All pending and future actions will
43+ -- | resolve immediately with the provided exception.
3944killVar ∷ ∀ eff a . AVar a → Error → AVarEff eff Unit
4045killVar avar err = Fn .runFn4 _killVar Left Right avar err
4146
47+ -- | Sets the value of the AVar. If the AVar is already filled, it will be
48+ -- | queued until the value is emptied. Multiple puts will resolve in order as
49+ -- | the AVar becomes available. Returns an effect which will remove the
50+ -- | callback from the pending queue.
4251putVar ∷ ∀ eff a . AVar a → a → AVarCallback eff Unit → AVarEff eff (AVarEff eff Unit )
4352putVar avar value cb = Fn .runFn5 _putVar Left Right avar value cb
4453
54+ -- | Attempts to synchronously fill an AVar. If the AVar is already filled,
55+ -- | this will do nothing. Returns true or false depending on if it succeeded.
4556tryPutVar ∷ ∀ eff a . AVar a → a → AVarEff eff Boolean
4657tryPutVar avar value = Fn .runFn4 _tryPutVar Left Right avar value
4758
59+ -- | Takes the AVar value, leaving it empty. If the AVar is already empty,
60+ -- | the callback will be queued until the AVar is filled. Multiple takes will
61+ -- | resolve in order as the AVar fills. Returns an effect which will remove
62+ -- | the callback from the pending queue.
4863takeVar ∷ ∀ eff a . AVar a → AVarCallback eff a → AVarEff eff (AVarEff eff Unit )
4964takeVar avar cb = Fn .runFn4 _takeVar Left Right avar cb
5065
66+ -- | Attempts to synchronously take an AVar value, leaving it empty. If the
67+ -- | AVar is empty, this will return `Nothing`.
5168tryTakeVar ∷ ∀ eff a . AVar a → AVarEff eff (Maybe a )
5269tryTakeVar avar = Fn .runFn5 _tryTakeVar Left Right Nothing Just avar
5370
71+ -- | Reads the AVar value. Unlike `takeVar`, this will not leave the AVar empty.
72+ -- | If the AVar is empty, this will queue until it is filled. Multiple reads
73+ -- | will resolve at the same time, as soon as possible.
5474readVar ∷ ∀ eff a . AVar a → AVarCallback eff a → AVarEff eff (AVarEff eff Unit )
5575readVar avar cb = Fn .runFn4 _readVar Left Right avar cb
5676
77+ -- | Attempts to synchronously read an AVar. If the AVar is empty, this will
78+ -- | return `Nothing`.
5779tryReadVar ∷ ∀ eff a . AVar a → AVarEff eff (Maybe a )
5880tryReadVar avar = Fn .runFn3 _tryReadVar Nothing Just avar
5981
0 commit comments