Documentation ¶
Overview ¶
Package actor provides basic support for building actors for use in the Agent.
Example ¶
// Unless explicitly stated otherwise all files in this repository are licensed // under the Apache License Version 2.0. // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. package main import ( "context" "fmt" "time" ) func main() { type component struct { ch chan int actor Goroutine } c := &component{ ch: make(chan int), } run := func(ctx context.Context) { for { select { case v := <-c.ch: fmt.Printf("GOT: %d\n", v) case <-ctx.Done(): fmt.Println("Stopping") return } } } c.actor.Start(run) c.ch <- 1 c.ch <- 2 c.actor.Stop(context.Background()) } func run(ctx context.Context) { tkr := time.NewTicker(time.Millisecond) for { select { case <-tkr.C: fmt.Println("tick") case <-ctx.Done(): return } } }
Output: GOT: 1 GOT: 2 Stopping
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Goroutine ¶
type Goroutine struct {
// contains filtered or unexported fields
}
Goroutine manages an actor goroutine, supporting starting and later stopping the goroutine. This is one-shot: once started and stopped, the goroutine cannot be started again.
The zero value is a valid initial state.
func (*Goroutine) HookLifecycle ¶
HookLifecycle connects this goroutine to the given fx.Lifecycle, starting and stopping it with the lifecycle. Use this method _or_ the Start and Stop methods, but not both.
Click to show internal directories.
Click to hide internal directories.