|
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 |
2 | 14 |
|
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