From da4c7723fbc793ea088ca5e06d884f45f5e96a91 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Wed, 7 Aug 2024 16:48:29 +0530 Subject: [PATCH] Update the multiple receive with url fetches --- .../multiple-receive/multiple_receive.bal | 24 ++++++++++--------- .../multiple-receive/multiple_receive.out | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/multiple-receive/multiple_receive.bal b/examples/multiple-receive/multiple_receive.bal index 60272d287d..4c1734f29c 100644 --- a/examples/multiple-receive/multiple_receive.bal +++ b/examples/multiple-receive/multiple_receive.bal @@ -1,27 +1,29 @@ +import ballerina/http; import ballerina/io; import ballerina/lang.runtime; type Result record { - int a; - int b; + json|error a; + json|error b; }; public function main() { worker w1 { - 2 -> w3; + fetch("https://postman-echo.com/get?worker=w1") -> function; } worker w2 { runtime:sleep(2); - 3 -> w3; + fetch("https://postman-echo.com/get?worker=w2") -> function; } - worker w3 returns json { - // The worker waits until both values are received. - Result result = <- {a: w1, b: w2}; - return result.toJson(); - } - - json result = wait w3; + // The worker waits until both values are received. + Result result = <- {a: w1, b: w2}; io:println(result); } + +function fetch(string url) returns json|error { + http:Client cl = check new (url); + record {map args;} payload = check cl->get(""); + return payload.args.'worker; +} diff --git a/examples/multiple-receive/multiple_receive.out b/examples/multiple-receive/multiple_receive.out index 138f4d93de..19ccb127eb 100644 --- a/examples/multiple-receive/multiple_receive.out +++ b/examples/multiple-receive/multiple_receive.out @@ -1,2 +1,2 @@ $ bal run multiple_receive.bal -{"a":2,"b":3} +{"a":"w1","b":"w2"}