actor

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: Apache-2.0, BSD-3-Clause, ISC Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrActorDead = errors.New("actor dead")
View Source
var ErrClosed = errors.New("promise closed")

Functions

This section is empty.

Types

type Base

type Base[T any] struct {
	// contains filtered or unexported fields
}

func (*Base[T]) Active

func (b *Base[T]) Active() bool

Active returns true if the task is currently running. Note that by the time this function returns, the value it returns may already be stale.

func (*Base[T]) Err

func (b *Base[T]) Err() error

Err returns the last error, if a task returns one.

func (*Base[T]) Send

func (b *Base[T]) Send(ctx context.Context, value T) (*Promise[any], error)

Send will block until the message is sent or the context is cancelled.

func (*Base[T]) Shutdown

func (b *Base[T]) Shutdown(ctx context.Context) error

Shutdown shuts down the task, if it's running. Shutdown will wait for the current instance of the task to fully shut down.

func (*Base[T]) TrySend

func (b *Base[T]) TrySend(ctx context.Context, value T) (*Promise[any], bool)

TrySend tries to send if it wouldn't block. The boolean result is set to true when the message is successfully sent, false otherwise.

func (*Base[T]) TryStart

func (b *Base[T]) TryStart(ctx context.Context, callback func(context.Context, *Task[T]) error) bool

TryStart returns true if started, or false if there's already a running task.

type Message

type Message[T any] struct {
	Context context.Context
	Value   T
	Promise *Promise[any]
}

type Promise

type Promise[T any] struct {
	// contains filtered or unexported fields
}

Promise is a simple promise-like object.

func NewPromise

func NewPromise[T any]() *Promise[T]

func (*Promise[T]) Close

func (p *Promise[T]) Close()

func (*Promise[T]) Reject

func (p *Promise[T]) Reject(err error)

func (*Promise[T]) Resolve

func (p *Promise[T]) Resolve(value T)

func (*Promise[T]) Wait

func (p *Promise[T]) Wait(ctx context.Context) (T, error)

type Task

type Task[T any] struct {
	// contains filtered or unexported fields
}

func (*Task[T]) Receive

func (t *Task[T]) Receive() (Message[T], error)

Receive receives the next message in the mailbox. Note that the promise needs to be resolved or rejected for every message.

Jump to

Keyboard shortcuts

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