Swan Lake Beta3 is here.
import ballerina/io;

// Usually it is an error to import a module without using it, but if you want to import a module because of what its initialization does,
//  then use `as _` as in this example.
import ballerina/grpc as _;

// A module can have an `init` function just like an object. 
// The initialization of a module ends by called its `init` function if there is one.
function init() {
    io:println("Hello world");
}

Module Lifecycle

All modules are initialized at program startup. Module initialization is ordered so that if module A imports module B, then module A is initialized after module B. The initialization phase ends by calling the main function if there is one.

A module’s listeners are registered during module initialization. If there are registered listeners, then the initialization phase is followed by the listening phase.

The listening phase starts by calling the start method on each registered listener. The listening phase is terminated by signal (e.g. SIGINT, SIGTERM).

import ballerina/io;
import ballerina/grpc as _;

Usually it is an error to import a module without using it, but if you want to import a module because of what its initialization does, then use as _ as in this example.

function init() {
    io:println("Hello world");
}

A module can have an init function just like an object. The initialization of a module ends by called its init function if there is one.

bal run module_lifecycle.bal
Hello world
import ballerina/io;

// Usually it is an error to import a module without using it, but if you want to import a module because of what its initialization does,
//  then use `as _` as in this example.
import ballerina/grpc as _;

// A module can have an `init` function just like an object. 
// The initialization of a module ends by called its `init` function if there is one.
function init() {
    io:println("Hello world");
}

Module Lifecycle

All modules are initialized at program startup. Module initialization is ordered so that if module A imports module B, then module A is initialized after module B. The initialization phase ends by calling the main function if there is one.

A module’s listeners are registered during module initialization. If there are registered listeners, then the initialization phase is followed by the listening phase.

The listening phase starts by calling the start method on each registered listener. The listening phase is terminated by signal (e.g. SIGINT, SIGTERM).

import ballerina/io;
import ballerina/grpc as _;

Usually it is an error to import a module without using it, but if you want to import a module because of what its initialization does, then use as _ as in this example.

function init() {
    io:println("Hello world");
}

A module can have an init function just like an object. The initialization of a module ends by called its init function if there is one.

bal run module_lifecycle.bal
Hello world
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand