Skip to content

Commit

Permalink
Add record type to store result
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Apr 10, 2024
1 parent a297d90 commit a70d6ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
14 changes: 7 additions & 7 deletions examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,13 @@
"verifyOutput": true,
"isLearnByExample": true
},
{
"name": "Multiple receive",
"url": "multiple-receive",
"verifyBuild": true,
"verifyOutput": true,
"isLearnByExample": true
},
{
"name": "Inter-worker failure propagation",
"url": "inter-worker-failure-propagation",
Expand Down Expand Up @@ -1467,13 +1474,6 @@
"verifyBuild": true,
"verifyOutput": true,
"isLearnByExample": true
},
{
"name": "Multiple receive",
"url": "multiple-receive",
"verifyBuild": true,
"verifyOutput": true,
"isLearnByExample": true
}
]
},
Expand Down
15 changes: 10 additions & 5 deletions examples/multiple-receive/multiple_receive.bal
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import ballerina/io;
import ballerina/lang.runtime;

type Result record {
int w1;
int w2;
};

public function main() {
worker w1 {
2 -> w3;
Expand All @@ -11,13 +16,13 @@ public function main() {
3 -> w3;
}

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

map<int> results = wait w3;
io:println(results["w1"]);
io:println(results["w2"]);
Result results = wait w3;
io:println(results.w1);
io:println(results.w2);
}
2 changes: 1 addition & 1 deletion examples/multiple-receive/multiple_receive.metatags
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
description: This BBE demonstrates the multiple receive action.
description: This BBE demonstrates the use of the multiple receive action in inter-worker communication
keywords: ballerina, ballerina by example, bbe, worker, multiple receive

0 comments on commit a70d6ae

Please sign in to comment.