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

Implementing delay operator #481

Open
emlautarom1 opened this issue Feb 21, 2022 · 3 comments
Open

Implementing delay operator #481

emlautarom1 opened this issue Feb 21, 2022 · 3 comments

Comments

@emlautarom1
Copy link

I've been playing around with Conduit for the past few days and I'm looking for something like a 'delay'. For reference, I've had a pleasant experience using RxJS and one of the provided operators is delay. I find it interesting that Conduit doesn't provide something like that out-of-the-box.

I implemented this kind of feature using the following:

delay :: MonadIO m => Int -> ConduitT a a m ()
delay n = awaitForever $ \v -> do
  liftIO $ threadDelay n
  yield v

It looks very simple so I assume that something is wrong or I'm not considering some edge case. So far it has worked great, but I would like to know if this implementation is correct and if anyone is interested in adding it to the Combinators module.

@snoyberg
Copy link
Owner

The implementation looks fine to me. This function doesn’t exist because no one’s ever expressed a need for it. I don’t see a problem with adding it if you’re interested in making a PR

@emlautarom1
Copy link
Author

Sure, I'll be glad to make a PR. I would appreciate any hint regarding tests for this operator!

@snoyberg
Copy link
Owner

I’d recommend testing that at least the right amount of time has passed after rubbing a pipeline with delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants