Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Azer0s committed Jan 12, 2021
1 parent 847c665 commit f080266
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Wait()

### GenServers

quacktors supports Elixir style GenServers! And it even gets better: quacktors can even filter GenServer functions by operation and message type by parsing the methods name via reflection.
As part of the default component set, quacktors supports Elixir style GenServers. The handlers for these are configured via the method names via reflection. So a GenServer with a `Call` handler for a `PrintRequest` would look like so:

```go
type PrintRequest struct {
Expand All @@ -158,6 +158,8 @@ pid := Spawn(genserver.New(Printer{}))
res, err := genserver.Call(pid, PrintRequest{})
```

So you don't even have to write your own actors if you don't want to. Cool, isn't it?

### On message order and reception

In quacktors, message order is guaranteed from one actor to another. Meaning that if you send messages from A to B, they will arrive in order. The same is true for remote actors.
Expand Down
19 changes: 10 additions & 9 deletions component/genserver/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,29 @@ import (
//Casts are great when you only care about the actor receiving
//a message but not if the operation was successful.
//
//The third and final way is a normal send. This is completely
//asynchronous and acts like any other actor would (just that
//a GenServer offers some more framework sugar to make it easier
//to work with).
//The third and final way is a normal send (the handlers for which
//are postfixed with "Info"). This is completely asynchronous and
//acts like any other actor would (just that a GenServer offers
//some more framework sugar to make it easier to work with).
//
//Usage
//
//The handlers links for a custom GenServer are described via
//the method names. The general format of a GenServer handler
//is:
// Handle + MessageType + (Call | Cast |or nothing for a send handler)
// Handle + MessageType + (Call | Cast | Info)
//So to handle a GenericMessage Cast, the method name would look
//like so:
// func (m myGenServer) HandleGenericMessageCast(ctx *Context, message GenericMessage)
//
//And a handler for a KillMessage Call would look like this:
// func (m myGenServer) HandleKillMessageCall(ctx *Context, message KillMessage) Message
//
//A default handler for a DownMessage would look like this:
// func (m myGenServer) HandleDownMessage(ctx *Context, message DownMessage)
// func (m myGenServer) HandleDownMessageInfo(ctx *Context, message DownMessage)
//
//Note that the Call method returns a message, while the normal
//send handler and the Cast handler don't. This is because
//send handler (Info) and the Cast handler don't. This is because
//a Call is the only GenServer operation that can directly return
//something to the sender.
//
Expand All @@ -54,8 +57,6 @@ import (
// func (m myGenServer) HandleCast(ctx *Context, message GenericMessage)
// func (m myGenServer) HandleCall(ctx *Context, message GenericMessage) Message
// func (m myGenServer) HandleInfo(ctx *Context, message GenericMessage)
//(HandleInfo is a innuendo to the Elixir GenServer and is
//the "catch-all" for normal sends)
type GenServer interface {
InitGenServer(ctx *quacktors.Context)
}
Expand Down

0 comments on commit f080266

Please sign in to comment.