Skip to content

Commit

Permalink
Add multiple receive bbe
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Apr 8, 2024
1 parent 85bffa7 commit 4f52a8a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,13 @@
"verifyOutput": true,
"isLearnByExample": true
},
{
"name": "Multiple receive",
"url": "multiple-receive",
"verifyBuild": true,
"verifyOutput": true,
"isLearnByExample": true
},
{
"name": "Named workers and futures",
"url": "named-workers-and-futures",
Expand Down
23 changes: 23 additions & 0 deletions examples/multiple-receive/multiple_receive.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ballerina/io;
import ballerina/lang.runtime;

public function main() {
worker w1 {
2 -> w3;
}

worker w2 {
runtime:sleep(2);
3 -> w3;
}

worker w3 returns map<int> {
// worker waits until both values are received.
map<int> result = <- {w1, w2};
return result;
}

map<int> results = wait w3;
io:println(results["w1"]);
io:println(results["w2"]);
}
7 changes: 7 additions & 0 deletions examples/multiple-receive/multiple_receive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Multiple receive

The multiple receive action allows receiving messages from multiple workers.

::: code multiple_receive.bal :::

::: out multiple_receive.out :::
2 changes: 2 additions & 0 deletions examples/multiple-receive/multiple_receive.metatags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: This BBE demonstrates the multiple receive action.
keywords: ballerina, ballerina by example, bbe, worker, multiple receive
3 changes: 3 additions & 0 deletions examples/multiple-receive/multiple_receive.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ bal run multiple_receive.bal
2
3

0 comments on commit 4f52a8a

Please sign in to comment.