protoactor-go: github.com/AsynkronIT/protoactor-go/scheduler Index | Examples | Files

package scheduler

import "github.com/AsynkronIT/protoactor-go/scheduler"

Index

Examples

Package Files

timer.go

func WithContext Uses

func WithContext(ctx actor.SenderContext) timerOptionFunc

WithContext configures the scheduler to use ctx rather than the default, EmptyRootContext.

type CancelFunc Uses

type CancelFunc func()

type Stopper Uses

type Stopper interface {
    Stop()
}

type TimerScheduler Uses

type TimerScheduler struct {
    // contains filtered or unexported fields
}

A scheduler utilizing timers to send messages in the future and at regular intervals.

Use the timer scheduler to repeatedly send messages to an actor.

Code:

var wg sync.WaitGroup
wg.Add(2)

count := 0
props := actor.PropsFromFunc(func(c actor.Context) {
    switch v := c.Message().(type) {
    case string:
        count++
        fmt.Println(count, v)
        wg.Done()
    }
})

pid := actor.EmptyRootContext.Spawn(props)

s := scheduler.NewTimerScheduler()
cancel := s.SendRepeatedly(1*time.Millisecond, 1*time.Millisecond, pid, "Hello")
wg.Wait()
cancel()

Output:

1 Hello
2 Hello

func NewTimerScheduler Uses

func NewTimerScheduler(opts ...timerOptionFunc) *TimerScheduler

NewTimerScheduler creates a new scheduler using the EmptyRootContext. Additional options may be specified to override the default behavior.

func (*TimerScheduler) RequestOnce Uses

func (s *TimerScheduler) RequestOnce(delay time.Duration, pid *actor.PID, message interface{}) CancelFunc

RequestOnce waits for the duration to elapse and then calls actor.SenderContext.Request to forward the message to pid.

func (*TimerScheduler) RequestRepeatedly Uses

func (s *TimerScheduler) RequestRepeatedly(delay, interval time.Duration, pid *actor.PID, message interface{}) CancelFunc

RequestRepeatedly waits for the initial duration to elapse and then calls Request to forward the message to pid repeatedly for each interval.

func (*TimerScheduler) SendOnce Uses

func (s *TimerScheduler) SendOnce(delay time.Duration, pid *actor.PID, message interface{}) CancelFunc

SendOnce waits for the duration to elapse and then calls actor.SenderContext.Send to forward the message to pid.

func (*TimerScheduler) SendRepeatedly Uses

func (s *TimerScheduler) SendRepeatedly(initial, interval time.Duration, pid *actor.PID, message interface{}) CancelFunc

SendRepeatedly waits for the initial duration to elapse and then calls Send to forward the message to pid repeatedly for each interval.

Package scheduler imports 4 packages (graph). Updated 2019-08-07. Refresh now. Tools for package owners.