Skip to content

2. Actor Model

kooinam edited this page Sep 3, 2020 · 1 revision

Fab.io's Actor Model features the following:

  • Event Driven

Every actor has one address (mailbox) and one worker. Instead of calling methods, an actor's worker carry out a delegated task upon receiving event arriving at its mailbox.

  • Loop Based

Every actor runs its piece of logic in an infinite game loop while it's active and receives an Update event every second. To register an action to respond to the corresponding event, do the following:

// RegisterActions used to register actions corresponding to events received by actor
func (bot *Bot) RegisterActorActions(actionsHandler *actors.ActionsHandler) {
	actionsHandler.RegisterAction("Update", bot.Run)
}

// Run used to run bot logic regularly 
func (bot *Bot) Run(context *actors.Context) error {
	var err error

	// bot do something

	return err
}
  • Synchronized Worker

Deadlock arises when multiple workers are blocked waiting for each other while accessing shared resources. Actor Model comes to rescue by having single synchronized worker and ensuring resources integrity and minimal usage of lock.

  • Distributed Solutions

Getting Started

WIP

Clone this wiki locally