A Glimpse Inside Workers In Ballerina

The values returned from each future will be taken together as the result as a record or map.public function main() { worker w1 returns int { int x = 30; return x; } worker w2 returns int { int y = 15; int g = y + 1; return g; } // Wait for all the given workers 'w1' and 'w2' to complete // The result of the 2 workers will be assigned to a map..// with the key as the worker names if a key is not provided // explicitly..map<int> result = wait {w1, w2};}public function main() { worker w1 returns int { int x = 100; return x; } worker w2 returns string { string s = "Hello Natasha!!.How are you?" return s; } // Wait for all the given workers 'w1' and 'w2' to complete // The result of the 2 workers will be assigned to a record with // the field name as the worker name if a field name is not // provided..record{ int w1; string w2; } result = wait {w1, w2};}Flush ActionFlush action is used by workers to check if all messages sent to a given worker is successfully delivered i.e..it will wait until all messages are sent from the current worker to the given worker..If the receiving worker fails with an error or panics, then the error will be propagated to the waiting strand.public function main() { worker w1 { int a = 10; a -> w2; a + 10 -> w2; // Flush all messages sent to worker 'w2'. Worker 'w1' will // stop here until all messages are sent or for a failure in // 'w2'. error? result = flush w2; a -> w2; // Flush all messages sent to all workers from worker 'w1'. // Worker 'w1' will stop here until all messages are sent to // the workers or for any failures by the workers. error? result = flush; } worker w2 { int b; b = <- w1; b = <- w1; b = <- w1; } worker w3 { int a = <- w1; }}So this was just a brief overview of workers and their actions in Ballerina. Further examples can be found here. You can try these out by downloading ballerina.Now as for how to end with a bang? Well, that’s another blog post for another time 🙂 🙂 Till we meet again 🙂 :). More details

Leave a Reply