Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windowing operations #14

Open
natefaubion opened this issue Dec 8, 2018 · 0 comments
Open

Windowing operations #14

natefaubion opened this issue Dec 8, 2018 · 0 comments

Comments

@natefaubion
Copy link
Contributor

natefaubion commented Dec 8, 2018

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

rgrover added a commit to rgrover/purescript-avar that referenced this issue May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant