-
Notifications
You must be signed in to change notification settings - Fork 0
/
future_actor.go
44 lines (36 loc) · 975 Bytes
/
future_actor.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
package goactor
import (
"github.com/hedisam/goactor/internal/intlpid"
"github.com/hedisam/goactor/pid"
"time"
)
type FutureActor struct {
mailbox Mailbox
self *pid.PID
msgHandler MessageHandler
}
func newFutureActor(mailbox Mailbox, self intlpid.InternalPID) *FutureActor {
return &FutureActor{
mailbox: mailbox,
self: pid.ToPID(self),
}
}
func (a *FutureActor) Self() *pid.PID {
return a.self
}
func (a *FutureActor) Receive(handler MessageHandler) error {
defer a.dispose()
a.msgHandler = handler
return a.mailbox.Receive(handler, a.systemMessageHandler)
}
func (a *FutureActor) ReceiveWithTimeout(timeout time.Duration, handler MessageHandler) error {
defer a.dispose()
a.msgHandler = handler
return a.mailbox.ReceiveWithTimeout(timeout, handler, a.systemMessageHandler)
}
func (a *FutureActor) systemMessageHandler(sysMsg interface{}) (loop bool) {
return a.msgHandler(sysMsg)
}
func (a *FutureActor) dispose() {
a.mailbox.Dispose()
}