phony: Index | Files

package phony

import ""

Package phony is a small actor model library for Go, inspired by the causal messaging system in the Pony programming language. An Actor is an interface satisfied by a lightweight Inbox struct. Structs that embed an Inbox satisfy an interface that allows them to send messages to eachother. Messages are functions of 0 arguments, typically closures, and should not perform blocking operations. Message passing is asynchronous, causal, and fast. Actors implemented by the provided Inbox struct are scheduled to prevent messages queues from growing too large, by pausing at safe breakpoints when an Actor detects that it sent something to another Actor whose inbox is flooded.


Package Files

actor.go doc.go

func Block Uses

func Block(actor Actor, action func())

Block adds a message to an Actor's Inbox, which will be executed at some point in the future. It then blocks until the Actor has finished running the provided function. Block meant exclusively as a convenience function for non-Actor code to send messages and wait for responses. If an Actor calls Block, then it may cause a deadlock, so Act should always be used instead.

type Actor Uses

type Actor interface {
    Act(Actor, func())
    // contains filtered or unexported methods

Actor is the interface for Actors, based on their ability to receive a message from another Actor. It's meant so that structs which embed an Inbox can satisfy a mutually compatible interface for message passing.

type Inbox Uses

type Inbox struct {
    // contains filtered or unexported fields

Inbox is an ordered queue of messages which an Actor will process sequentially. Messages are meant to be in the form of non-blocking functions of 0 arguments, often closures. The intent is for the Inbox struct to be embedded in other structs, causing them to satisfy the Actor interface, and then the Actor is used to access any protected fields of the struct. It is up to the user to ensure that memory is used safely, and that messages do not contain blocking operations. An Inbox must not be copied after first use.

func (*Inbox) Act Uses

func (a *Inbox) Act(from Actor, action func())

Act adds a message to an Inbox, which will be executed by the inbox's Actor at some point in the future. When one Actor sends a message to another, the sender is meant to provide itself as the first argument to this function. If the sender argument is non-nil and the receiving Inbox has been flooded, then backpressure is applied to the sender. This backpressue cause the sender stop processing messages at some point in the future until the receiver has caught up with the sent message. A nil first argument is valid, but should only be used in cases where backpressure is known to be unnecessary, such as when an Actor sends a message to itself or sends a response to a request (where it's the request sender's fault if they're flooded by responses).

Package phony imports 3 packages (graph) and is imported by 3 packages. Updated 2020-06-13. Refresh now. Tools for package owners.