fuel v0.1.0 Fuel.Ctx View Source

Provides functions for interacting with a ctx.

The ctx is based on the golang context.Context and provides many of the same functional features.

Using a ctx provides a common thread of data that can be used all through your application. It can be used in plug, grpc, graphql or just within your application to facilitate testing.

You can include things like

  • implementation of behaviours
  • Authentication information
  • ids - request, trace etc
  • deadlines
  • arbitrary values

@see https://github.com/tsloughter/ctx

Link to this section Summary

Functions

Fetch a new deadline

Fetches a ctx from a kw list or map or returns a new one

puts a ctx into a kwlist or map

true if the deadline has not yet exceeded. false

True when the time is earlier than the deadline. False if the deadline has elapsed

Fetches an implementation from the given context.

Fetches the implementation for the given behavioru from the given context.

Get a value at a key. Missing values will raise a KeyError

Get a value at a key. Missing values will return the default

Fetch a new deadline

Set a value at a key in the context. Any valid term may be used as a key

Provide a new ctx with a deadline set to elapse after the given time period

Set a deadline on an existing ctx

Store the implementation of a behaviour in a context

provides a new ctx with the given value

Store a value on

Provide a new ctx with the given values

Link to this section Types

Link to this section Functions

Fetch a new deadline

Link to this function

ctx_from(options)

View Source
ctx_from(source() | nil) :: t()

Fetches a ctx from a kw list or map or returns a new one

Link to this function

ctx_into(ctx, source)

View Source
ctx_into(:ctx.t(), source()) :: source()

puts a ctx into a kwlist or map

true if the deadline has not yet exceeded. false

Link to this function

deadline_exceeded?(ctx)

View Source
deadline_exceeded?(t()) :: boolean()

True when the time is earlier than the deadline. False if the deadline has elapsed

Link to this function

fetch_impl(ctx, behaviour)

View Source
fetch_impl(:ctx.t(), behaviour_and_impl :: module()) :: impl()

Fetches an implementation from the given context.

If no implementation has been explicitly provided, use the behaviour module as the implementation

Link to this function

fetch_impl(ctx, behaviour, default_impl)

View Source
fetch_impl(:ctx.t(), behaviour(), default_impl :: impl()) :: impl()

Fetches the implementation for the given behavioru from the given context.

If no implementation has been explicitly provided, fall back to the deafult implementation provided

Get a value at a key. Missing values will raise a KeyError

Get a value at a key. Missing values will return the default

Fetch a new deadline

Set a value at a key in the context. Any valid term may be used as a key

Link to this function

with_deadline_after(value, time_unit)

View Source

Provide a new ctx with a deadline set to elapse after the given time period

Link to this function

with_deadline_after(ctx, value, time_unit)

View Source

Set a deadline on an existing ctx

Link to this function

with_impl(ctx, behaviour, impl)

View Source
with_impl(:ctx.t(), behaviour(), impl()) :: :ctx.t()

Store the implementation of a behaviour in a context

This is useful for changing out behaviours in things like tests where you want to use Mox.

@see fetch_impl/2, fetch_impl/3

provides a new ctx with the given value

Link to this function

with_value(ctx, key, value)

View Source

Store a value on

Provide a new ctx with the given values