Erlang - spawn


Advertisements

This is used to create a new process and initialize it.

Syntax

spawn(Function)

Parameters

  • Function − The function which needs to be spawned.

Return Value

This method returns a process id.

For example

-module(helloworld). 
-export([start/0]). 

start() ->
   spawn(fun() -> server("Hello") end). 

server(Message) ->
   io:fwrite("~p",[Message]).

Output

When we run the above program, we will get the following result.

“Hello”
erlang_distributed_programming.htm
Advertisements