@@ -24,9 +24,9 @@ import Data.Maybe (Maybe(..))
2424import Effect (Effect )
2525import Effect.Exception (Error )
2626
27- type AVarCallback a = (Either Error a → Effect Unit )
27+ type AVarCallback a = (Either Error a -> Effect Unit )
2828
29- foreign import data AVar ∷ Type → Type
29+ foreign import data AVar :: Type -> Type
3030
3131type role AVar representational
3232
@@ -36,92 +36,92 @@ data AVarStatus a
3636 | Empty
3737
3838-- | Creates a new empty AVar.
39- foreign import empty ∷ ∀ a . Effect (AVar a )
39+ foreign import empty :: forall a . Effect (AVar a )
4040
4141-- | Creates a fresh AVar with an initial value.
42- new ∷ ∀ a . a → Effect (AVar a )
42+ new :: forall a . a -> Effect (AVar a )
4343new = _newVar
4444
4545-- | Kills the AVar with an exception. All pending and future actions will
4646-- | resolve immediately with the provided exception.
47- kill ∷ ∀ a . Error → AVar a → Effect Unit
47+ kill :: forall a . Error -> AVar a -> Effect Unit
4848kill err avar = Fn .runFn3 _killVar ffiUtil err avar
4949
5050-- | Sets the value of the AVar. If the AVar is already filled, it will be
5151-- | queued until the value is emptied. Multiple puts will resolve in order as
5252-- | the AVar becomes available. Returns an effect which will remove the
5353-- | callback from the pending queue.
54- put ∷ ∀ a . a → AVar a → AVarCallback Unit → Effect (Effect Unit )
54+ put :: forall a . a -> AVar a -> AVarCallback Unit -> Effect (Effect Unit )
5555put value avar cb = Fn .runFn4 _putVar ffiUtil value avar cb
5656
5757-- | Attempts to synchronously fill an AVar. If the AVar is already filled,
5858-- | this will do nothing. Returns true or false depending on if it succeeded.
59- tryPut ∷ ∀ a . a → AVar a → Effect Boolean
59+ tryPut :: forall a . a -> AVar a -> Effect Boolean
6060tryPut value avar = Fn .runFn3 _tryPutVar ffiUtil value avar
6161
6262-- | Takes the AVar value, leaving it empty. If the AVar is already empty,
6363-- | the callback will be queued until the AVar is filled. Multiple takes will
6464-- | resolve in order as the AVar fills. Returns an effect which will remove
6565-- | the callback from the pending queue.
66- take ∷ ∀ a . AVar a → AVarCallback a → Effect (Effect Unit )
66+ take :: forall a . AVar a -> AVarCallback a -> Effect (Effect Unit )
6767take avar cb = Fn .runFn3 _takeVar ffiUtil avar cb
6868
6969-- | Attempts to synchronously take an AVar value, leaving it empty. If the
7070-- | AVar is empty, this will return `Nothing`.
71- tryTake ∷ ∀ a . AVar a → Effect (Maybe a )
71+ tryTake :: forall a . AVar a -> Effect (Maybe a )
7272tryTake avar = Fn .runFn2 _tryTakeVar ffiUtil avar
7373
7474-- | Reads the AVar value. Unlike `take`, this will not leave the AVar empty.
7575-- | If the AVar is empty, this will queue until it is filled. Multiple reads
7676-- | will resolve at the same time, as soon as possible.
77- read ∷ ∀ a . AVar a → AVarCallback a → Effect (Effect Unit )
77+ read :: forall a . AVar a -> AVarCallback a -> Effect (Effect Unit )
7878read avar cb = Fn .runFn3 _readVar ffiUtil avar cb
7979
8080-- | Attempts to synchronously read an AVar. If the AVar is empty, this will
8181-- | return `Nothing`.
82- tryRead ∷ ∀ a . AVar a → Effect (Maybe a )
82+ tryRead :: forall a . AVar a -> Effect (Maybe a )
8383tryRead avar = Fn .runFn2 _tryReadVar ffiUtil avar
8484
8585-- | Synchronously checks the status of an AVar.
86- status ∷ ∀ a . AVar a → Effect (AVarStatus a )
86+ status :: forall a . AVar a -> Effect (AVarStatus a )
8787status avar = Fn .runFn2 _status ffiUtil avar
8888
89- isEmpty ∷ ∀ a . AVarStatus a → Boolean
89+ isEmpty :: forall a . AVarStatus a -> Boolean
9090isEmpty = case _ of
91- Empty → true
92- _ → false
91+ Empty -> true
92+ _ -> false
9393
94- isFilled ∷ ∀ a . AVarStatus a → Boolean
94+ isFilled :: forall a . AVarStatus a -> Boolean
9595isFilled = case _ of
96- Filled _ → true
97- _ → false
96+ Filled _ -> true
97+ _ -> false
9898
99- isKilled ∷ ∀ a . AVarStatus a → Boolean
99+ isKilled :: forall a . AVarStatus a -> Boolean
100100isKilled = case _ of
101- Killed _ → true
102- _ → false
103-
104- foreign import _newVar ∷ ∀ a . a → Effect (AVar a )
105- foreign import _killVar ∷ ∀ a . Fn.Fn3 FFIUtil Error (AVar a ) (Effect Unit )
106- foreign import _putVar ∷ ∀ a . Fn.Fn4 FFIUtil a (AVar a ) (AVarCallback Unit ) (Effect (Effect Unit ))
107- foreign import _tryPutVar ∷ ∀ a . Fn.Fn3 FFIUtil a (AVar a ) (Effect Boolean )
108- foreign import _takeVar ∷ ∀ a . Fn.Fn3 FFIUtil (AVar a ) (AVarCallback a ) (Effect (Effect Unit ))
109- foreign import _tryTakeVar ∷ ∀ a . Fn.Fn2 FFIUtil (AVar a ) (Effect (Maybe a ))
110- foreign import _readVar ∷ ∀ a . Fn.Fn3 FFIUtil (AVar a ) (AVarCallback a ) (Effect (Effect Unit ))
111- foreign import _tryReadVar ∷ ∀ a . Fn.Fn2 FFIUtil (AVar a ) (Effect (Maybe a ))
112- foreign import _status ∷ ∀ a . Fn.Fn2 FFIUtil (AVar a ) (Effect (AVarStatus a ))
101+ Killed _ -> true
102+ _ -> false
103+
104+ foreign import _newVar :: forall a . a -> Effect (AVar a )
105+ foreign import _killVar :: forall a . Fn.Fn3 FFIUtil Error (AVar a ) (Effect Unit )
106+ foreign import _putVar :: forall a . Fn.Fn4 FFIUtil a (AVar a ) (AVarCallback Unit ) (Effect (Effect Unit ))
107+ foreign import _tryPutVar :: forall a . Fn.Fn3 FFIUtil a (AVar a ) (Effect Boolean )
108+ foreign import _takeVar :: forall a . Fn.Fn3 FFIUtil (AVar a ) (AVarCallback a ) (Effect (Effect Unit ))
109+ foreign import _tryTakeVar :: forall a . Fn.Fn2 FFIUtil (AVar a ) (Effect (Maybe a ))
110+ foreign import _readVar :: forall a . Fn.Fn3 FFIUtil (AVar a ) (AVarCallback a ) (Effect (Effect Unit ))
111+ foreign import _tryReadVar :: forall a . Fn.Fn2 FFIUtil (AVar a ) (Effect (Maybe a ))
112+ foreign import _status :: forall a . Fn.Fn2 FFIUtil (AVar a ) (Effect (AVarStatus a ))
113113
114114type FFIUtil =
115- { left ∷ ∀ a b . a → Either a b
116- , right ∷ ∀ a b . b → Either a b
117- , nothing ∷ ∀ a . Maybe a
118- , just ∷ ∀ a . a → Maybe a
119- , killed ∷ ∀ a . Error → AVarStatus a
120- , filled ∷ ∀ a . a → AVarStatus a
121- , empty ∷ ∀ a . AVarStatus a
115+ { left :: forall a b . a -> Either a b
116+ , right :: forall a b . b -> Either a b
117+ , nothing :: forall a . Maybe a
118+ , just :: forall a . a -> Maybe a
119+ , killed :: forall a . Error -> AVarStatus a
120+ , filled :: forall a . a -> AVarStatus a
121+ , empty :: forall a . AVarStatus a
122122 }
123123
124- ffiUtil ∷ FFIUtil
124+ ffiUtil :: FFIUtil
125125ffiUtil =
126126 { left: Left
127127 , right: Right
0 commit comments