Community Theatre helps you put on shows when you don't have the resources to be on Broadway.
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
Find a file
James Harton d83e53d596 Merge branch 'renovate/configure' into 'master'
Configure Renovate

See merge request jimsy/community-theatre!1
2020-07-21 02:51:37 +00:00
lib Allow for unconstrained subscriptions too. 2020-04-11 16:33:31 +12:00
test Allow for unconstrained subscriptions too. 2020-04-11 16:33:31 +12:00
.formatter.exs First post 2020-04-07 14:48:53 +12:00
.gitignore Set up CI, licenses, etc. 2020-04-07 15:01:21 +12:00
.gitlab-ci.yml Set up CI, licenses, etc. 2020-04-07 15:01:21 +12:00
LICENSE Set up CI, licenses, etc. 2020-04-07 15:01:21 +12:00
mix.exs Credo should only happen in dev/test. 2020-04-11 16:43:30 +12:00
mix.lock Basic functionality is working. 2020-04-10 16:42:38 +12:00
README.md Basic functionality is working. 2020-04-10 16:42:38 +12:00
renovate.json Add renovate.json 2020-07-21 02:30:58 +00:00

CommunityTheatre

Community theatre is similar but opposite to the broadway package. It's designed to handle ingesting data from sources at various update frequencies and emit them again to consumers at a constrained rate. Particularly useful for devices of constrained resources.

Usage

Any Erlang term can be published to arbitrary topics at any rate:

for bottle_count <- Enum.reverse(0..99) do
  CommunityTheatre.publish(:bottles_of_beer_on_the_wall, bottle_count)
  Process.sleep(100)
end

However subscribers will only receive updates at the frequency they specify. You can implement the CommunityTheatre.RateLimiter behaviour to specify how to deal with extra methods. This package includes the Drop and Average limiters. Drop is used by default if none is specified.

iex> CommunityTheatre.subscribe(:bottles_of_beer_on_the_wall, 0.3, CommunityTheatre.RateLimiter.Average)
...> for bottle_count <- Enum.reverse(0..99) do
...>   CommunityTheatre.publish(:bottles_of_beer_on_the_wall, bottle_count)
...>   Process.sleep(100)
...> end
...> flush
{CommunityTheatre,
%CommunityTheatre.Message{
  payload: 83,
  received_at: ~U[2020-04-10 04:31:58.215609Z],
  topic: :bottles_of_beer_on_the_wall
}}
{CommunityTheatre,
%CommunityTheatre.Message{
  payload: 50,
  received_at: ~U[2020-04-10 04:32:01.548600Z],
  topic: :bottles_of_beer_on_the_wall
}}
{CommunityTheatre,
%CommunityTheatre.Message{
  payload: 17,
  received_at: ~U[2020-04-10 04:32:04.881524Z],
  topic: :bottles_of_beer_on_the_wall
}}

Installation

If available in Hex, the package can be installed by adding community_theatre to your list of dependencies in mix.exs:

def deps do
  [
    {:community_theatre, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/community_theatre.