Portal Game v0.1.0 Portal.Door View Source

Using agents, portal doors maintain state.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Get the data currently in the door.

Pops a value from the door.

Pushes value into the door.

Resets the door to []

Starts a door with the given color.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Get the data currently in the door.

Example

iex> Portal.Door.start_link(:rust)
iex> Portal.Door.push(:rust, 1)
iex> Portal.Door.get(:rust)
[1]

Pops a value from the door.

Returns {:ok, value} if there is a value or :error if the portal is empty.

Example

iex> Portal.Door.start_link(:black)
iex> Portal.Door.pop(:black)
:error

iex> Portal.Door.start_link(:white)
iex> Portal.Door.push(:white, 1)
iex> Portal.Door.pop(:white)
{:ok, 1}

Pushes value into the door.

Example

iex> Portal.Door.start_link(:pink)
iex> Portal.Door.push(:pink, 1)
:ok

Resets the door to []

Example

iex> Portal.Door.start_link(:grey)
iex> Portal.Door.push(:grey, 1)
iex> Portal.Door.reset(:grey)
iex> Portal.Door.get(:grey)
[]

Starts a door with the given color.

The color is given as a name so we can identify the door by color name instead of using a PID.

Example

iex> {:ok, pid} = Portal.Door.start_link(:yellow) # {:ok, #<PID<something.something.something>}
iex> is_pid(pid)
true