New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add alternate receive
bbe
#5290
base: master
Are you sure you want to change the base?
Add alternate receive
bbe
#5290
Conversation
534ede9
to
15f0dbe
Compare
|
||
worker w6 returns int|error? { | ||
// Alternate receive action waits until a message that is not an error is received | ||
// when error is not an expected static type. Since `w4` returns an error it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "error is not an expected static type" part correct?
Also, with
import ballerina/io;
import ballerina/lang.runtime;
public function main() {
worker w4 returns error? {
int value = 10;
if value == 10 {
return error("Error in worker 1");
}
value -> w6;
}
worker w5 returns error? {
runtime:sleep(2);
boolean b = true;
if b {
return error("x");
}
3 -> w6;
}
worker w6 returns int|error? {
// Alternate receive action waits until a message that is not an error is received
// when error is not an expected static type. Since `w4` returns an error it
// waits further and sets the value that is received from `w5`.
int|error a = <- w4 | w5;
return a;
}
int|error? valueW6 = wait w6;
io:println(valueW6);
}
when error is in the expected type, we still wait for the second error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when error is in the expected type, we still wait for the second error?
I think no.
@HindujaB can u confirm the behavior here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, we don't evaluate the error return type when passing the message.
The alternate wait will wait until a message that is not an error is received. Or if errors are received in all the channels, then the result is the last such error.
In the above case, the int|error a = <- w4 | w5;
will return error("x")
.
|
||
worker w6 returns int|error? { | ||
// Alternate receive action waits until a message that is not an error is received | ||
// when error is not an expected static type. Since `w4` returns an error it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when error is in the expected type, we still wait for the second error?
I think no.
@HindujaB can u confirm the behavior here?
3a18ef4
to
1cdc81c
Compare
1cdc81c
to
2ea5379
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: lochana-chathura <39232462+lochana-chathura@users.noreply.github.com>
dd3240d
to
0ea111e
Compare
cbc1f16
to
138bc4b
Compare
138bc4b
to
5a17e31
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
function fetch(string url) returns json|error { | ||
http:Client cl = check new (url); | ||
map<json> payload = check cl->get(""); | ||
return payload["args"]; | ||
} | ||
|
||
function getJsonProperty(json|error data) returns json|error? => | ||
data is error ? data.message() : data.'worker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function fetch(string url) returns json|error { | |
http:Client cl = check new (url); | |
map<json> payload = check cl->get(""); | |
return payload["args"]; | |
} | |
function getJsonProperty(json|error data) returns json|error? => | |
data is error ? data.message() : data.'worker; | |
function fetch(string url) returns map<json>|error { | |
http:Client cl = check new (url); | |
record {| map<json> args; |} payload = check cl->/; | |
return payload.args; | |
} | |
function getJsonProperty(map<json>|error data) returns json|error => | |
data is error ? data.message() : data.'worker; |
Quality Gate passedIssues Measures |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the |
Purpose
$subject
Part of ballerina-platform/ballerina-dev-website#8856