-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5399 from poorna2152/master_worker_with_on_fail
[Master] Add named worker with on fail clause bbe
- Loading branch information
Showing
5 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ballerina/io; | ||
|
||
public function main() { | ||
int[] values = [2, 3, 4, 5]; | ||
int value = 0; | ||
|
||
worker w1 { | ||
int index = check getIndex(values, value); | ||
index -> function; | ||
} on fail { | ||
// Handle the error thrown in the worker body. | ||
-1 -> function; | ||
} | ||
|
||
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"); |
7 changes: 7 additions & 0 deletions
7
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Named worker with on fail clause | ||
|
||
The `on fail` clause can be used with a named worker, to handle any errors that occur within the worker's body. | ||
|
||
::: code named_worker_with_on_fail_clause.bal ::: | ||
|
||
::: out named_worker_with_on_fail_clause.out ::: |
2 changes: 2 additions & 0 deletions
2
examples/named-worker-with-on-fail-clause/named_worker_with_on_fail_clause.metatags
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description: This BBE demonstrates the use of `on fail` clause with named workers | ||
keywords: ballerina, ballerina by example, bbe, worker, named workers, on fail |
2 changes: 2 additions & 0 deletions
2
examples/named-worker-with-on-fail-clause/named_worker_with_on_fail_clause.out
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$ bal run named_worker_with_on_fail_clause.bal | ||
-1 |