Skip to content

Windowing operations #14

Open
Open
@natefaubion

Description

@natefaubion

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions