Process

Processes

Names and subjects for addressing a running process.

Local names use namedSubject. For a registered name on another connected node, use remoteSubject (needs --sname / --name distribution).

This module is selm stdlib for target = "erlang". Browser apps use the client platform Process (Id / spawn / kill / Task sleep), not Subject / call / listen. See fixtures/process_dual and examples/02_counter.

Types

Name

type Name a = Name

A registry name for a process that handles messages of type a.

Examples

Process.newName "counter"

Subject

type Subject a = Subject

An address for sending messages of type a.

Examples

Process.namedSubject name

Pid

type Pid = Pid

The operating-system identity of a running process.

Examples

Process.self

Values

newName

newName : String -> Name a

Create a registry name for a process.

Examples

Process.newName "counter"

namedSubject

namedSubject : Name a -> Subject a

Address a process by its registered name on this node.

Examples

Process.namedSubject name

remoteSubject

remoteSubject : Name a -> Node -> Subject a

Address a registered name on another node.

Both nodes must be distributed and share a cookie. The remote process still uses listen on that name locally.

Examples

Process.remoteSubject name otherNode

newSubject

newSubject : Subject a

Allocate a fresh subject (reply address).

Examples

Process.newSubject

send

send : Subject a -> a -> ()

Send a message to a subject.

Examples

Process.send subject Incr

call

call : Subject a -> Int -> (Subject b -> a) -> b

Send a message and wait for the reply.

Examples

Process.call subject 5000 (\reply -> Get reply)

reply

reply : Subject a -> a -> Cmd msg

Answer a Process.call from update. The command sends the value to the reply subject.

Examples

Process.reply replyTo 42

listen

listen : Name a -> (a -> msg) -> Sub msg

Deliver messages sent to a name into the running program.

Examples

Process.listen name GotMsg

self

self : Pid

The pid of the calling process.

Examples

Process.self

sleep

sleep : Int -> ()

Block the current process for the given milliseconds.

Examples

Process.sleep 100