Code Snippets Ballerina

Short texts Ballerina 🧑‍💻 Code snippets Ballerina ✍️ Reading lists Ballerina 👀

Named Worker Return Values

import ballerina/io; function demo(string s) returns int|error { // Named workers have a return type, which defaults to nil // if not specified. worker A returns int|error { // A return statement in a named worker terminates // the worker, not the function. // Similarly, when `check` is used and the expression evaluates // to […]

Inter-Worker Message Passing

import ballerina/io; public function main() { worker A { // Use `-> W` to send a message to worker `W`. 1 -> B; 2 -> C; } worker B { // Use `

Named Workers and Futures

import ballerina/io; function demo() returns future { worker A returns int { return 42; } // Futures and workers are the same thing. // A reference to a named worker can be implicitly converted into a future. return A; } type FuncInt function () returns int; function startInt(FuncInt f) returns future { // `start` is […]