Deadline v0.2.0 Deadline View Source

Deadline is a small library for managing deadlines and for performing deadline propagation across systems. It uses process dictionary both for performance and to make the library more ergonomic.

# Set a deadline in milliseconds
Deadline.set(1_000)

# Perform some work that takes longer than a second
Deadline.work(fn ->
  Service.call()
end)

# Won't be called because we've exceeded our deadline
Deadline.work(fn ->
  Service.call()
end)

if Deadline.reached?() do
  :cancel
else
  do_some_work()
end

Link to this section Summary

Functions

Returns the deadline context.

Checks if a deadline has been reached or exceeded.

Sets the deadline context. If a integer is passed it is assumed to be the desired deadline in milliseconds. This function also accepts a full deadline context. This is most commonly used when a deadline has already been set and the context needs to be propagated to another BEAM process.

Returns the remaining time before the dealine is reached, in a given unit. Defaults to :native units.

Performs some work. If the deadline has already been exceeded than the function will not be called and the code will not be executed. If the deadline is reached, the calling process will receive an exit signal with the reason of :canceled. If you do not want the calling process to exit, you will need to trap exits and handle any necessary cleanup.

Link to this section Functions

Returns the deadline context.

Checks if a deadline has been reached or exceeded.

Sets the deadline context. If a integer is passed it is assumed to be the desired deadline in milliseconds. This function also accepts a full deadline context. This is most commonly used when a deadline has already been set and the context needs to be propagated to another BEAM process.

Link to this function

time_remaining(unit \\ :native)

View Source

Returns the remaining time before the dealine is reached, in a given unit. Defaults to :native units.

Performs some work. If the deadline has already been exceeded than the function will not be called and the code will not be executed. If the deadline is reached, the calling process will receive an exit signal with the reason of :canceled. If you do not want the calling process to exit, you will need to trap exits and handle any necessary cleanup.