actor

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2018 License: MIT Imports: 3 Imported by: 0

README

actor

Build Status Go Report Card GoDoc GitHub license

Implementation Actor model in Go.

Design

Actor = {receive chan interface{}}

Usage

Install
go get github.com/dannypsnl/actor
Example
import (
    "github.com/dannypsnl/actor"
)

type Echo struct {
    actor.Actor
}

func (e *Echo) Fun() {
    msg := <-e.Receive
    switch msg.(type) {
    case strWithSender:
        m := msg.(strWithSender)
        m.sender <- m.str
        e.Fun()
    case closing:
        close(e.Receive)
    default:
        panic("Just don't want to resolve U!")
    }
}

type closing struct{}

type strWithSender struct {
    sender chan string
    str    string
}

func main() {
    echoPid := actor.Spawn(&Echo{}, []interface{}{})
    self := make(chan string)
    echoPid <- strWithSender{self, "Hi"}
    result := <-self
    println(result) // expected: Hi
    echoPid <- closing{}
}

Note

Erlang won't receive one message twice.

Documentation

Overview

actor pkg will help you have a best experience with Actor model programming

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Spawn

func Spawn(actor actorable, startArgs []interface{}) chan interface{}

Spawn help user start an actor like Erlang way. The Actor can execute in Spawn require method Fun & match interface Actorable

Types

type Actor

type Actor struct {
	Receive chan interface{}
}

Actor contains a receive channel help user don't need to understand how actor work at first. Just embedded Actor into their custom actor to use it

func (*Actor) Init

func (a *Actor) Init()

func (*Actor) Pid

func (a *Actor) Pid() chan interface{}

Pid return actor's pid

Directories

Path Synopsis
example
echo command
say_hello command

Jump to

Keyboard shortcuts

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