Open
Description
Something like this was requested in #7, and I think it could be supported fairly easily, and would likely simplify implementations of purescript-concurrent-queues
since all the queue machinery exists in AVar anyway.
data Operation
= Ignore -- Do nothing with the queue
| Fail Error -- Propagate an exception to the callback
| Halt Error -- Kill the internal queue and propagate the exception
| PushHead -- Push callback onto the head
| PushTail -- Push callback onto the tail
| DropHead Error -- Drop the head, and push onto the tail
| DropTail Error -- Drop the tail, and push onto the head
| SwapHead Error -- Replace the head
| SwapTail Error -- Replace the tail
windowPut :: forall a b. (Int -> Operation) -> a -> AVar a -> AVarCallback Unit -> Effect (Effect Unit)
This would have variations for windowTake
, tryWindowPut
. tryWindowTake
isn't necessary. It would be straightforward to implement queue strategies on top, which could be bundled up as newtypes in a separate library.
putMax :: forall a. Int -> Error -> a -> AVar a -> AVarCallback Unit -> Effect (Effect Unit)
putMax max err = windowPut go
where
go n
| n < max = PushTail
| otherwise = Fail err
putSliding :: forall a. Int -> Error -> a -> AVar a -> AVarCallback Unit -> Effect (EFfect Unit)
putSliding max err = windowPut go
where
go n
| n < max = PushTail
| otherwise = DropHead err
Metadata
Metadata
Assignees
Labels
No labels