View Source Handler (handler v0.4.3)

A helper for running functions that might take too long, or use too much memory.

Handler will run these functions in their own process and "take care of" problematic processes.

Link to this section Summary

Functions

Run a potentially dangerous function in a safe way.

Link to this section Types

Specs

bytes() :: non_neg_integer()

Specs

Specs

milliseconds() :: non_neg_integer()

Specs

opt() :: {:max_ms, milliseconds()} | {:max_heap_bytes, bytes()}

Specs

opts() :: [opt()]

Link to this section Functions

Run a potentially dangerous function in a safe way.

examples

Examples

iex> Handler.run(fn -> 1 + 1 end)
2

iex> Handler.run(fn -> :timer.sleep(200) end, max_ms: 10)
{:error, %Handler.Timeout{message: "Took more than 10ms to complete"}}

iex> Handler.run(fn -> Enum.map(1..10_000, & &1*100) end, max_heap_bytes: 4096)
{:error, %Handler.OOM{message: "Process tried to use more than 4096 bytes of memory"}}

iex> Handler.run(fn -> Process.exit(self(), :i_am_ded) end)
{:error, %Handler.ProcessExit{message: "Process exited with :i_am_ded", reason: :i_am_ded}}