roc icon indicating copy to clipboard operation
roc copied to clipboard

Can programs for a given platform run operations in parallel?

Open mainrs opened this issue 2 years ago • 6 comments

I have written a platform with support for HTTP requests for website crawling.

Currently a user calls a function called crawl with a given start url. And the function returns a response object one can operate on.

A user can submit a new crawl by calling the crawl function again with a function callback that gets called once the response is available.

But everything is sequential on the roc side of things. Is it possible to make it concurrent?

For example use generators to submit crawled data or new requests instead of calling functions. And the platform can pull the generator for new instances.

mainrs avatar Dec 13 '23 12:12 mainrs

We have Task.map2 in the plans as a concurrency primitive. It would allow you to run two tasks in parallel. It will take some time until it's ready though.

As a temporary hack, you could submit a list of urls to your platform and return nothing (Task {} YourErrorType), and then use Task.loop with a sleep time of your choosing. In that loop you can ask the platform if it finished crawling more urls and process the results as they come in. That processing on the roc side would be single threaded but now the platform could execute requests in parallel.

Anton-4 avatar Dec 13 '23 12:12 Anton-4

We have Task.map2 in the plans as a concurrency primitive. It would allow you to run two tasks in parallel. It will take some time until it's ready though.

Is it possible to generalize over n arguments without having to create a new method each time? Similar to Rust's const generics feature? I mean not right now, but would the language allow for this (easily to be added)?

mainrs avatar Feb 16 '24 10:02 mainrs

I think so but I asked on zulip to make sure.

Anton-4 avatar Feb 16 '24 12:02 Anton-4

Yes, Folkert confirmed mapN should work by recursively using map2 to map over N tasks.

Anton-4 avatar Feb 16 '24 12:02 Anton-4

Yes, Folkert confirmed mapN should work by recursively using map2 to map over N tasks.

That would make calling semantics easier for sure. This would still mean that only 2 tasks get executed in parallel, is that correct?

mainrs avatar Feb 16 '24 13:02 mainrs

@folkertdev

Anton-4 avatar Feb 16 '24 14:02 Anton-4

This question is pretty old, so I'm assuming it's no longer relevant and closing the issue. Sorry if your question wasn't answered. If you still have questions about this, please feel free to re-open this issue, open a new issue, or ask on Zulip.

skyqrose avatar Nov 03 '24 01:11 skyqrose