# `Mojoler.Sched`
[🔗](https://github.com/thanos/mojoler/blob/v0.1.0/lib/mojoler/sched.ex#L1)

Scheduler jobs.

`burn/1` and `hold/2` run on a dirty CPU scheduler. `io_ping/0` runs on a
dirty I/O scheduler. An Elixir timeout does not cancel the native work.
`Task.yield/2` returning `nil` means the caller stopped waiting. The native
function runs until it returns.

# `burn`

```elixir
@spec burn(non_neg_integer()) :: :ok
```

Spins for `milliseconds` on a dirty CPU scheduler, then returns `:ok`.

`milliseconds` is an integer greater than or equal to 0. The loop reads the
monotonic clock. A caller timeout does not stop it.

## Raises

  * `ArgumentError` when `milliseconds` is not an integer, or is negative

## Examples

    iex> Mojoler.Sched.burn(0)
    :ok

    iex> Mojoler.Sched.burn(-1)
    ** (ArgumentError) argument error

# `hold`

```elixir
@spec hold(binary(), non_neg_integer()) :: binary()
```

Copies `bin`, spins for `milliseconds`, and returns the same bytes.

The borrowed view of `bin` is released before the spin. The loop reads the
copy. `milliseconds` is an integer greater than or equal to 0.

## Returns

The copied binary.

## Raises

  * `ArgumentError` when `bin` is not a binary, or `milliseconds` is not
    an integer greater than or equal to 0

## Examples

    iex> Mojoler.Sched.hold(<<1, 2, 3>>, 0)
    <<1, 2, 3>>

    iex> Mojoler.Sched.hold(<<1::7>>, 0)
    ** (ArgumentError) argument error

# `io_ping`

```elixir
@spec io_ping() :: :ok
```

Returns `:ok` from a dirty I/O scheduler.

There are no arguments.

## Examples

    iex> Mojoler.Sched.io_ping()
    :ok

# `load_nif`

```elixir
@spec load_nif() :: :ok | {:error, term()}
```

Loads `priv/native/libsched.so`.

A second call returns `{:error, {:reload, charlist}}`.

## Examples

    iex> Mojoler.Sched.load_nif()
    {:error, {:reload, ~c"NIF library already loaded (reload disallowed since OTP 20)."}}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
