y_process v0.1.5 YProcess.Backend behaviour

Behaviour to implement backends for the communication between YProcesses.

Summary

Functions

Creates channels using a backend module

Deletes channels using a backend module

Emits messages. Uses a backend module to send a message to a list of channels. Also uses a function transform/2 that receives the channel and the message to make modifications to the message before sending it

Joins the channels using a backend module

Leaves the channels using a backend module

Callbacks

Callback to create a channel

Callback to delete a channel

Callback used to send a message to a channel

Callback used to make a process with pid a channel

Callback used to make a process with pid leave a channel

Functions

create(module, channels)

Specs

create(module, channels) ::
  :ok |
  :no_return when channels: YProcess.channels

Creates channels using a backend module.

delete(module, channels)

Specs

delete(module, channels) ::
  :ok |
  :no_return when channels: YProcess.channels

Deletes channels using a backend module.

emit(module, list, message, transform)

Specs

emit(module, channels, message, (channel, message -> term)) ::
  :ok |
  :no_return when channel: YProcess.channel, channels: YProcess.channels, message: term

Emits messages. Uses a backend module to send a message to a list of channels. Also uses a function transform/2 that receives the channel and the message to make modifications to the message before sending it.

If it fails to send the message to any of the channels, sends an exit signal to the calling process. If no error is found while sending the message to any of the channels return :ok.

join(module, channels)

Specs

join(module, channels) ::
  :ok |
  :no_return when channels: YProcess.channels

Joins the channels using a backend module.

leave(module, channels)

Specs

leave(module, channels) ::
  :ok |
  :no_return when channels: YProcess.channels

Leaves the channels using a backend module.

Callbacks

create(channel)

Specs

create(channel) ::
  :ok |
  {:error, reason} when channel: YProcess.channel, reason: term

Callback to create a channel.

Returns :ok when the channel has been created succesfully.

Returns {:error, reason} when the channel couldn’t be created.

delete(channel)

Specs

delete(channel) ::
  :ok |
  {:error, reason} when channel: YProcess.channel, reason: term

Callback to delete a channel.

Returns :ok when the channel has been deleted succesfully.

Returns {:error, reason} when the channel couldn’t be deleted.

emit(channel, message)

Specs

emit(channel, message) ::
  :ok |
  {:error, reason} when channel: YProcess.channel, message: term, reason: term

Callback used to send a message to a channel.

Returns :ok when the message is sent.

Returns {:error, reason} when the message couldn’t be sent.

join(channel, pid)

Specs

join(channel, pid) ::
  :ok |
  {:error, reason} when channel: YProcess.channel, reason: term

Callback used to make a process with pid a channel.

Returns :ok when the process joins the channel successfully.

Returns {:error, reason} when the process couldn’t join the channel.

leave(channel, pid)

Specs

leave(channel, pid) ::
  :ok |
  {:error, reason} when channel: YProcess.channel, reason: term

Callback used to make a process with pid leave a channel.

Returns :ok when the process leaves the channel successfully.

Returns {:error, reason} when the process couldn’t leave the channel.