Class: Proc

Serl.Proc(nodeName, procIndex, localNode)

Constructor for objects analogous to an OTP process.

Constructor

new Proc(nodeName, procIndex, localNode)

Parameters:
Name Type Description
nodeName module:Serl.Node#name
procIndex module:Serl.ProcIndex
localNode module:Serl.Node

The node which spawns the new proc, then stores it in its node.procMap.

This procMap should be the ONLY direct reference to the process, otherwise interactions with this process should only occur via send/receive i.e. message-passing.

Properties:
Name Type Description
toString function

module:Serl.Proc#toString

defaultMailHandler function

module:Serl.Proc#defaultMailHandler

send function

module:Serl.Proc#send

receive function

module:Serl.Proc#receive

node module:Serl.Node

Reference to argument passed in parameter#3; doing this is questionable. To be reviewed.

nodeIndex module:Serl.NodeIndex
pid module:Serl.Pid

Unique identifier for this proc, on this Node.

mailbox Array

A stack for messages received by this proc.

mailHandler function

A method which determines how the process handles messages it receives. This may include storing them in the mailbox, checking messages already in the mailbox, executing other logic, or simply ignoring them.

Source:
To Do:
  • Dependence on localNode is questionable; review.
  • Do we need to validate argument types here?
  • Would performance improve if these were static methods?
  • 'registered processes'

Members

node :module:Serl.Node

Type:
Source:
To Do:
  • Review, do we want this here?

Methods

defaultMailHandler()

When the next message come in, they will be held in this.mailbox in their order of arrival. No attempt is made to match them to any further logical branches

Source:

receive()

See OTP docs.

In the body of a function passed to spawn/n, usage would be in the example below, where this refers to the proc which was spawned.

Source:
See:
  • How does a process handle received messages?
    Text: https://erlangbyexample.org/send-receive
    Illustrated: https://learnyousomeerlang.com/more-on-multiprocessing
    
     When a process receives a message, the message is
     appended to the mailbox.
    
     The receive block will try each message in the mailbox (one
     by one), against that block's sequence of patterns, until
     one of the messages matches a pattern.
    
     When there is match, the message gets removed from
     the mailbox and the logic corresponding to the matched pattern
     will get executed. If there is no match,
     then that message remains in the mailbox, and the following
     message gets tried sequentially,
     against all of the receive block's patterns.
    
     If no messages in the mailbox match any pattern, the process,
     having tried all messages, and having exhausted all receive
     patterns, will get suspended until a new message arrives,
     and the message processing logic starts all over,
     beginning with the first message in the mailbox.
     
To Do:
  • extend example to include entire call to spawn/n
  • typecheck 'branches'? Should be iterable. Currently expects
  • type: [ [ 'function', 'function'] ]
  • Perhaps allow type: [ 'function', 'function' ] ?
  • Perhaps allow type: 'function' where this is just the branch?
Example
let awaited = await this.receive( branches )

 

send(dest, msg)

Sends a message from this process to another process.

Ultimately executes:

destinationProcess.mailHandler ( validMsg )
Parameters:
Name Type Description
dest module:Serl.Pid

A Pid object which addresses the local or remote process.

msg *

The message to be sent to the destination process.

Source:
To Do:
  • Validation/Proxy/Reassignment: ensure that nothing is passed by reference.
  • Validation of dest?

toString()

Overridden toString . Output is of the form:

[object Proc<0.1>]
Source:
To Do:
  • should this be made into a static method?