ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
167 stars 53 forks source link

Worker and/or futures support for variable numbers of workers with variable outcome #104

Open pzfreo opened 5 years ago

pzfreo commented 5 years ago

Description: Many consensus algorithms or business processes require starting n workers and waiting until some proportion (e.g. n/2+1) have completed. This is very difficult in Ballerina today because the only way seems to be to loop and sleep.

For example in the raft consensus algorithm, there are voting processes where a system sends out an election command in parallel to n servers and waits until more than half of the n servers have responded yes. n is variable and can change at runtime.

It seems the only way to do this today is to use "start" n times, and then loop through checking which are done and the responses. The result is either a tight loop or using runtime:sleep, neither of which seems ideal. It might be nice to have language support for this.

Suggested Labels: workers, concurrency, futures, wait

Code sample that shows issue: Not available

Related Issues:

jclark commented 5 years ago

I agree this would be useful.

jclark commented 5 years ago

The first idea that comes to mind for this is to have a library function with a parameter of type map<future<T>>, which would:

  1. wait for one future to complete
  2. remove the completed future from the map
  3. return a value of type [string,T] saying which future completed and what the completion was
pzfreo commented 5 years ago

That seems a very elegant solution to the problem.