@@ -24,9 +24,9 @@ import Data.Maybe (Maybe(..))
24
24
import Effect (Effect )
25
25
import Effect.Exception (Error )
26
26
27
- type AVarCallback a = (Either Error a → Effect Unit )
27
+ type AVarCallback a = (Either Error a -> Effect Unit )
28
28
29
- foreign import data AVar ∷ Type → Type
29
+ foreign import data AVar :: Type -> Type
30
30
31
31
type role AVar representational
32
32
@@ -36,92 +36,92 @@ data AVarStatus a
36
36
| Empty
37
37
38
38
-- | Creates a new empty AVar.
39
- foreign import empty ∷ ∀ a . Effect (AVar a )
39
+ foreign import empty :: forall a . Effect (AVar a )
40
40
41
41
-- | Creates a fresh AVar with an initial value.
42
- new ∷ ∀ a . a → Effect (AVar a )
42
+ new :: forall a . a -> Effect (AVar a )
43
43
new = _newVar
44
44
45
45
-- | Kills the AVar with an exception. All pending and future actions will
46
46
-- | resolve immediately with the provided exception.
47
- kill ∷ ∀ a . Error → AVar a → Effect Unit
47
+ kill :: forall a . Error -> AVar a -> Effect Unit
48
48
kill err avar = Fn .runFn3 _killVar ffiUtil err avar
49
49
50
50
-- | Sets the value of the AVar. If the AVar is already filled, it will be
51
51
-- | queued until the value is emptied. Multiple puts will resolve in order as
52
52
-- | the AVar becomes available. Returns an effect which will remove the
53
53
-- | 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 )
55
55
put value avar cb = Fn .runFn4 _putVar ffiUtil value avar cb
56
56
57
57
-- | Attempts to synchronously fill an AVar. If the AVar is already filled,
58
58
-- | 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
60
60
tryPut value avar = Fn .runFn3 _tryPutVar ffiUtil value avar
61
61
62
62
-- | Takes the AVar value, leaving it empty. If the AVar is already empty,
63
63
-- | the callback will be queued until the AVar is filled. Multiple takes will
64
64
-- | resolve in order as the AVar fills. Returns an effect which will remove
65
65
-- | 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 )
67
67
take avar cb = Fn .runFn3 _takeVar ffiUtil avar cb
68
68
69
69
-- | Attempts to synchronously take an AVar value, leaving it empty. If the
70
70
-- | AVar is empty, this will return `Nothing`.
71
- tryTake ∷ ∀ a . AVar a → Effect (Maybe a )
71
+ tryTake :: forall a . AVar a -> Effect (Maybe a )
72
72
tryTake avar = Fn .runFn2 _tryTakeVar ffiUtil avar
73
73
74
74
-- | Reads the AVar value. Unlike `take`, this will not leave the AVar empty.
75
75
-- | If the AVar is empty, this will queue until it is filled. Multiple reads
76
76
-- | 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 )
78
78
read avar cb = Fn .runFn3 _readVar ffiUtil avar cb
79
79
80
80
-- | Attempts to synchronously read an AVar. If the AVar is empty, this will
81
81
-- | return `Nothing`.
82
- tryRead ∷ ∀ a . AVar a → Effect (Maybe a )
82
+ tryRead :: forall a . AVar a -> Effect (Maybe a )
83
83
tryRead avar = Fn .runFn2 _tryReadVar ffiUtil avar
84
84
85
85
-- | Synchronously checks the status of an AVar.
86
- status ∷ ∀ a . AVar a → Effect (AVarStatus a )
86
+ status :: forall a . AVar a -> Effect (AVarStatus a )
87
87
status avar = Fn .runFn2 _status ffiUtil avar
88
88
89
- isEmpty ∷ ∀ a . AVarStatus a → Boolean
89
+ isEmpty :: forall a . AVarStatus a -> Boolean
90
90
isEmpty = case _ of
91
- Empty → true
92
- _ → false
91
+ Empty -> true
92
+ _ -> false
93
93
94
- isFilled ∷ ∀ a . AVarStatus a → Boolean
94
+ isFilled :: forall a . AVarStatus a -> Boolean
95
95
isFilled = case _ of
96
- Filled _ → true
97
- _ → false
96
+ Filled _ -> true
97
+ _ -> false
98
98
99
- isKilled ∷ ∀ a . AVarStatus a → Boolean
99
+ isKilled :: forall a . AVarStatus a -> Boolean
100
100
isKilled = 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 ))
113
113
114
114
type 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
122
122
}
123
123
124
- ffiUtil ∷ FFIUtil
124
+ ffiUtil :: FFIUtil
125
125
ffiUtil =
126
126
{ left: Left
127
127
, right: Right
0 commit comments