-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vivid): add typed actor support and improve ask pattern
Implement support for typed actors in the vivid actor system, allowing for more type-safe interactions between actors and their references. This update introduces a new message type for handling actor reference type conversions and enhances the ask pattern to include typed responses. Additionally, the changes improve the dead letter handling by adding more detailed logging, and refactor the actor system shutdown process to ensure all pending messages are properly processed before closure.
- Loading branch information
1 parent
929d706
commit 4d12837
Showing
9 changed files
with
91 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package vivid | ||
|
||
import "time" | ||
import ( | ||
"time" | ||
) | ||
|
||
type ActorOption[T Actor] func(opts *ActorOptions[T]) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package vivid | ||
|
||
// ActorTyped 是用于将 Actor 消息类型化的接口,该接口继承了 Actor 和 ActorRef | ||
type ActorTyped interface { | ||
Actor | ||
ActorRef | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package vivid_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kercylan98/minotaur/minotaur/vivid" | ||
"testing" | ||
) | ||
|
||
type TestActor struct { | ||
vivid.ActorRef | ||
} | ||
|
||
type TestActorTyped interface { | ||
vivid.ActorTyped | ||
Println(string) | ||
} | ||
|
||
func (t *TestActor) OnReceive(ctx vivid.MessageContext) { | ||
switch m := ctx.GetMessage().(type) { | ||
case vivid.OnBoot: | ||
t.ActorRef = ctx | ||
case string: | ||
fmt.Println(m) | ||
} | ||
} | ||
|
||
func (t *TestActor) Println(s string) { | ||
t.Tell(s) | ||
} | ||
|
||
func TestActorOfT(t *testing.T) { | ||
system := vivid.NewActorSystem("test") | ||
ref := vivid.ActorOfT[*TestActor, TestActorTyped](&system) | ||
|
||
ref.Println("Hello, World!") | ||
|
||
system.Shutdown() | ||
} |