actor

package module
v0.0.0-...-34066dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2017 License: MIT Imports: 3 Imported by: 0

README

actor

For a more recent implementation of a Go actor framework see: https://github.com/tristanls/gotart

Stability: 1 - Experimental

Go language actor framework.

Documentation

Documentation

Overview

Go language actor framework.

Stability: 1 - Experimental (see: https://github.com/tristanls/stability-index#stability-1---experimental)

package main

import "fmt"
import "github.com/tristanls/go-actor"

// create an actor behavior
func Print(context actor.Context, msg actor.Message) {
  for _, param := range msg {
    fmt.Println(param.(string))
  }
  // starting go routines within an actor behavior is *NOT SAFE*
  // create actors instead, that's what they're for :)
}

// create a new actor configuration
func main() {
  config := actor.Configuration()
  config.Trace = true // trace message deliveries

  // create a new actor
  printer := config.Create(Print)

  // send a message to an actor
  printer <- actor.Message{"hello world"}

  // wait for actor configuration to finish
  config.Wait()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActorConfiguration

type ActorConfiguration struct {
	Trace bool
	// contains filtered or unexported fields
}

ActorConfiguration holds the state of an actor configuration To wait for all actors to finish call ActorConfiguration.Wait(), for example:

config := actor.Configuration()
// send some messages to actors
config.Wait() // wait for all actors to finish

"finish" in this case means that all actors finished execution and there are no more messages in flight

func Configuration

func Configuration() ActorConfiguration

Configuration creates a new actor configuration

func (*ActorConfiguration) Create

func (configuration *ActorConfiguration) Create(behavior Behavior) Reference

Create creates a new actor as part of the actor configuration

func (*ActorConfiguration) Wait

func (configuration *ActorConfiguration) Wait()

Wait blocks until the actor configuration finishes executing

type Become

type Become func(Behavior)

Become is a function that takes the behavior to handle the next message

type Behavior

type Behavior func(Context, Message)

Behavior describes how an actor will respond to a message. Actors are created with behaviors. Each behavior takes a context and a message to respond to. These behaviors are invoked by the library when executing an actor configuration.

type Context

type Context struct {
	Become Become
	Create func(Behavior) Reference
	Self   Reference
}

Context is passed to an actor behavior when it is invoked upon a message receive

type Message

type Message []interface{}

Message is just a slice of data

type Reference

type Reference chan<- Message

Reference to an actor is a channel that accepts messages

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL