@@ -30,30 +30,52 @@ foreign import data AVar ∷ Type → Type
30
30
31
31
foreign import data AVAR ∷ Effect
32
32
33
+ -- | Creates a fresh AVar.
33
34
foreign import makeEmptyVar ∷ ∀ eff a . AVarEff eff (AVar a )
34
35
36
+ -- | Creates a fresh AVar with an initial value.
35
37
foreign import makeVar ∷ ∀ eff a . a → AVarEff eff (AVar a )
36
38
39
+ -- | Synchronously checks whether an AVar currently has a value.
37
40
foreign import isEmptyVar ∷ ∀ eff a . AVar a → AVarEff eff Boolean
38
41
42
+ -- | Kills the AVar with an exception. All pending and future actions will
43
+ -- | resolve immediately with the provided exception.
39
44
killVar ∷ ∀ eff a . AVar a → Error → AVarEff eff Unit
40
45
killVar avar err = Fn .runFn4 _killVar Left Right avar err
41
46
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.
42
51
putVar ∷ ∀ eff a . AVar a → a → AVarCallback eff Unit → AVarEff eff (AVarEff eff Unit )
43
52
putVar avar value cb = Fn .runFn5 _putVar Left Right avar value cb
44
53
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.
45
56
tryPutVar ∷ ∀ eff a . AVar a → a → AVarEff eff Boolean
46
57
tryPutVar avar value = Fn .runFn4 _tryPutVar Left Right avar value
47
58
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.
48
63
takeVar ∷ ∀ eff a . AVar a → AVarCallback eff a → AVarEff eff (AVarEff eff Unit )
49
64
takeVar avar cb = Fn .runFn4 _takeVar Left Right avar cb
50
65
66
+ -- | Attempts to synchronously take an AVar value, leaving it empty. If the
67
+ -- | AVar is empty, this will return `Nothing`.
51
68
tryTakeVar ∷ ∀ eff a . AVar a → AVarEff eff (Maybe a )
52
69
tryTakeVar avar = Fn .runFn5 _tryTakeVar Left Right Nothing Just avar
53
70
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.
54
74
readVar ∷ ∀ eff a . AVar a → AVarCallback eff a → AVarEff eff (AVarEff eff Unit )
55
75
readVar avar cb = Fn .runFn4 _readVar Left Right avar cb
56
76
77
+ -- | Attempts to synchronously read an AVar. If the AVar is empty, this will
78
+ -- | return `Nothing`.
57
79
tryReadVar ∷ ∀ eff a . AVar a → AVarEff eff (Maybe a )
58
80
tryReadVar avar = Fn .runFn3 _tryReadVar Nothing Just avar
59
81
0 commit comments