-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
62 lines (52 loc) · 1.29 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Tideland Go Actor
//
// Copyright (C) 2019-2023 Frank Mueller / Tideland / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.
package actor // import "tideland.dev/go/actor"
//--------------------
// IMPORTS
//--------------------
import (
"context"
)
//--------------------
// OPTIONS
//--------------------
// Option defines the signature of an option setting function.
type Option func(act *Actor) error
// WithContext sets the context for the actor.
func WithContext(ctx context.Context) Option {
return func(act *Actor) error {
act.ctx = ctx
return nil
}
}
// WithQueueCap defines the channel capacity for actions sent to an Actor.
func WithQueueCap(c int) Option {
return func(act *Actor) error {
if c < defaultQueueCap {
c = defaultQueueCap
}
act.requests = make(chan *request, c)
return nil
}
}
// WithRecoverer sets a function for recovering from a panic
// during executing an action.
func WithRecoverer(recoverer Recoverer) Option {
return func(act *Actor) error {
act.recoverer = recoverer
return nil
}
}
// WithFinalizer sets a function for finalizing the
// work of a Loop.
func WithFinalizer(finalizer Finalizer) Option {
return func(act *Actor) error {
act.finalizer = finalizer
return nil
}
}
// EOF