together v0.2.1 Together

Group actions that need to be performed later together

What for?

  • group notifications before sending an email about them
  • only sending the very last value of a fast changing entity (renew: true)
  • only using the very first value of a changing entity in every fixed period (renew: false)

How to use

Start a Together.Worker to use it

You can start it by adding a worker to your app’s supervision tree

worker(Together.Worker, [[delay: 3000, renew: true], [name: Together.Worker]])

Or start it as you would any other GenServer

{:ok, pid} = Together.Worker.start_link(delay: 300, renew: true)

Make calls to the worker process:

  • Together.process(pid, "some_unique_name_or_id", a_function)
  • Together.process(pid, "id", Module, :func, [arg1, arg2, ...])
  • Together.process("something", some_func) you can omit the pid if the server is started with name Together.Worker

Summary

Functions

cancels queued action(s) for the given id

put in a function under the id to be processed (invoked) later

put in an mfa under the id to be processed (invoked/applied) later

Functions

cancel(pid \\ Together.Worker, id)
cancel(atom | pid, term) :: :ok | :error

cancels queued action(s) for the given id

process(pid \\ Together.Worker, id, func)
process(atom | pid, term, (... -> any)) :: :ok | no_return

put in a function under the id to be processed (invoked) later

process(pid \\ Together.Worker, id, m, f, a)
process(atom | pid, term, module, atom, list) ::
  :ok |
  no_return

put in an mfa under the id to be processed (invoked/applied) later