View Source DenoRider (DenoRider v0.1.1)

Summary

Functions

Returns a specification to start this module under a supervisor.

Same as eval/2, but it assumes that there is a process with the name DenoRider (the default if you don't provide a name to start_link/1).

Run the given JavaScript code and return the result.

Start a DenoRider process.

Start a JavaScript runtime and return a Task that finishes when runtime has started.

Stop a JavaScript runtime and return a Task that finishes when runtime has stopped.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec eval(binary()) :: {:ok, term()} | {:error, DenoRider.Error.t()}

Same as eval/2, but it assumes that there is a process with the name DenoRider (the default if you don't provide a name to start_link/1).

Examples

iex> DenoRider.eval("1 + 2")
{:ok, 3}
@spec eval(binary(), Keyword.t()) ::
  {:ok, term()} | {:error, DenoRider.Error.t()} | Task.t()

Run the given JavaScript code and return the result.

Options

  • :blocking - Indicates whether the NIF call should block until the JavaScript execution finishes or not. Blocking is more performant, but it can also cause problems if the call takes too long. The NIF documentation suggests that a NIF call shouldn't take more than 1 millisecond. Only set this to true if you need the performance boost and the execution stays below 1 millisecond or so. The default is false.
  • :name - The name of the DenoRider process. The default is DenoRider. Can't be provided if :runtime is provided.
  • :runtime - A runtime from start_runtime/1. If :runtime is provided, eval/2 will return a Task that finishes when the JavaScript exection finishes. Can't be provided if :name is provided.

Examples

iex> DenoRider.eval("1 + 2")
{:ok, 3}

iex> DenoRider.eval("1 + 2", blocking: true)
{:ok, 3}

iex> DenoRider.start_link(name: :foo)
iex> DenoRider.eval("1 + 2", name: :foo)
{:ok, 3}

iex> {:ok, runtime} = DenoRider.start_runtime() |> Task.await()
iex> DenoRider.eval("1 + 2", runtime: runtime) |> Task.await()

Start a DenoRider process.

Options

  • :name - The name of the process.

See start_runtime/1 for more options.

Examples

iex> DenoRider.start_link(name: MyApp.DenoRider)
iex> DenoRider.eval("1 + 2", name: MyApp.DenoRider)
{:ok, 3}
Link to this function

start_runtime(opts \\ [])

View Source
@spec start_runtime(Keyword.t()) :: Task.t()

Start a JavaScript runtime and return a Task that finishes when runtime has started.

Options

  • :main_module_path - Path to the main JavaScript module. The default is to start the runtime with an empty main module.

Examples

iex> DenoRider.start_runtime() |> Task.await()
@spec stop_runtime(DenoRider.Runtime.t()) :: Task.t()

Stop a JavaScript runtime and return a Task that finishes when runtime has stopped.

Examples

iex> {:ok, runtime} = DenoRider.start_runtime() |> Task.await()
iex> DenoRider.stop_runtime(runtime) |> Task.await()