-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the code and update description
- Loading branch information
1 parent
0398035
commit 6e9e6b9
Showing
2 changed files
with
7 additions
and
18 deletions.
There are no files selected for viewing
23 changes: 6 additions & 17 deletions
23
examples/named-worker-with-on-fail-clause/named_worker_with_on_fail_clause.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,20 @@ | ||
import ballerina/io; | ||
|
||
function getIndex(int[] values, int value) returns int|error { | ||
int? index = values.indexOf(value); | ||
if index is () { | ||
return error("value not found"); | ||
} | ||
|
||
return index; | ||
} | ||
|
||
public function main() { | ||
int[] values = [2, 3, 4, 5]; | ||
int value = 0; | ||
|
||
worker w1 { | ||
int index = check getIndex(values, value); | ||
index -> w2; | ||
index -> function; | ||
} on fail { | ||
// Handle the error thrown in the worker body. | ||
-1 -> w2; | ||
-1 -> function; | ||
} | ||
|
||
worker w2 returns int|error:NoMessage { | ||
int|error:NoMessage result = <- w1 | w1; | ||
return result; | ||
} | ||
|
||
int|error:NoMessage result = wait w2; | ||
int|error:NoMessage result = <- w1 | w1; | ||
io:println(result); | ||
} | ||
|
||
function getIndex(int[] values, int value) returns int|error => | ||
let int? index = values.indexOf(value) in index ?: error("value not found"); |
2 changes: 1 addition & 1 deletion
2
examples/named-worker-with-on-fail-clause/named_worker_with_on_fail_clause.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters