Skip to content

Commit b53ec1e

Browse files
committed
Add AVar bindings
1 parent 51169ff commit b53ec1e

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

src/Control/Monad/Aff/AVar.purs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,61 @@
1-
module Control.Monad.Aff.AVar where
1+
module Control.Monad.Aff.AVar
2+
( module Control.Monad.Eff.AVar
3+
, makeVar
4+
, makeEmptyVar
5+
, isEmptyVar
6+
, takeVar
7+
, tryTakeVar
8+
, putVar
9+
, tryPutVar
10+
, readVar
11+
, tryReadVar
12+
, killVar
13+
) where
214

3-
-- TODO
15+
import Prelude
16+
import Control.Monad.Aff (Aff, Canceler(..), makeAff)
17+
import Control.Monad.Eff (Eff)
18+
import Control.Monad.Eff.AVar (AVar, AVAR)
19+
import Control.Monad.Eff.AVar as AVar
20+
import Control.Monad.Eff.Class (liftEff)
21+
import Control.Monad.Eff.Exception (Error)
22+
import Data.Maybe (Maybe)
23+
24+
toCanceler eff. Eff eff Unit Canceler eff
25+
toCanceler = Canceler <<< const <<< liftEff
26+
27+
makeVar eff a. a Aff (avar AVAR | eff) (AVar a)
28+
makeVar = liftEff <<< AVar.makeVar
29+
30+
makeEmptyVar eff a. Aff (avar AVAR | eff) (AVar a)
31+
makeEmptyVar = liftEff AVar.makeEmptyVar
32+
33+
isEmptyVar eff a. AVar a Aff (avar AVAR | eff) Boolean
34+
isEmptyVar = liftEff <<< AVar.isEmptyVar
35+
36+
takeVar eff a. AVar a Aff (avar AVAR | eff) a
37+
takeVar avar = makeAff \k → do
38+
c ← AVar.takeVar avar k
39+
pure (toCanceler c)
40+
41+
tryTakeVar eff a. AVar a Aff (avar AVAR | eff) (Maybe a)
42+
tryTakeVar = liftEff <<< AVar.tryTakeVar
43+
44+
putVar eff a. AVar a a Aff (avar AVAR | eff) Unit
45+
putVar avar value = makeAff \k → do
46+
c ← AVar.putVar avar value k
47+
pure (toCanceler c)
48+
49+
tryPutVar eff a. AVar a a Aff (avar AVAR | eff) Boolean
50+
tryPutVar avar = liftEff <<< AVar.tryPutVar avar
51+
52+
readVar eff a. AVar a Aff (avar AVAR | eff) a
53+
readVar avar = makeAff \k → do
54+
c ← AVar.readVar avar k
55+
pure (toCanceler c)
56+
57+
tryReadVar eff a. AVar a Aff (avar AVAR | eff) (Maybe a)
58+
tryReadVar = liftEff <<< AVar.tryReadVar
59+
60+
killVar eff a. AVar a Error Aff (avar AVAR | eff) Unit
61+
killVar avar = liftEff <<< AVar.killVar avar

0 commit comments

Comments
 (0)