Can programs for a given platform run operations in parallel?
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.
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.
We have
Task.map2in 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)?
I think so but I asked on zulip to make sure.
Yes, Folkert confirmed mapN should work by recursively using map2 to map over N tasks.
Yes, Folkert confirmed
mapNshould work by recursively usingmap2to 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?
@folkertdev
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.