r/ryelang • u/middayc • 2d ago
Improving internals, wait-groups, higher level concurrency with Spawn
I'm improving the internals of Rye again. Still working on tarsnapper-rye implementation, that keeps being a source of ideas of what to improve and what to test better. I was working on goroutines and wait-groups and decided to experiment with a higher level concurrency mechanism. It makes sense for anync or concurrent tasks where we expect a result. So it's simpler to use and think about in a lot of use cases.
print "Starting background calculation"
task: spawn\with 21 fn { number } {
sleep 1000
number * 2
}
print "The main program can keep working"
sleep 300
print "Now waiting for the result..."
await task |printv "The result is {}"Or two specific tasks in parallel:
google: spawn\with https://www.google.com fn { url } {
.Get |length?
}
duckduckgo: spawn\with https://www.duckduckgo.com fn { url } {
.Get |length?
}
await google |printv "Google: {} characters"
await duckduckgo |printv "DuckDuckGo: {} characters"Still exploring this all ... you could use just ordinary map for example
sites: { https://www.google.com https://www.duckduckgo.com }
tasks: map sites {
.spawn\with fn { url } {
.Get .length?
}
}
map tasks { .await } |displayBut there could be some useful combinators that are task specific and hence make more sense. I don't have full picture yet, but it seems useful for more predictable / simpler specific concurrent cases than raw goroutines and channels. It also can handle errors more in tone with Rye, since results are returned. So I will definately explore this further.
Concurrency is usally a sore spot for many new languages, but basing Rye on Go - which has a super solid concurrency story - rewards us again.
For further discussion find our Discord - #homoiconic.
