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
/cc @felixSchl @kritzcreek
Something like this was requested in #7, and I think it could be supported fairly easily, and would likely simplify implementations of
purescript-concurrent-queuessince all the queue machinery exists in AVar anyway.This would have variations for
windowTake,tryWindowPut.tryWindowTakeisn't necessary. It would be straightforward to implement queue strategies on top, which could be bundled up as newtypes in a separate library./cc @felixSchl @kritzcreek