swiss v1.2.2 Swiss.Task View Source

Functions for writing async code that's testable asynchronously. You should import this module and use its macros as a DSL.

Right now it only makes sense to use this module if you're using Ecto's Sandbox adapter.

Example

defmodule YourProject.Task do
  import Swiss.Task
  async YourProject.Repo
  async_stream YourProject.Repo
end

defmodule YourProject.SomeModule do
  def some_async_function do
    YourProject.Task.async(fn -> end)
  end

  def some_other_async_function(enumerable) do
    YourProject.Task.async_stream(enumerable, fn -> end)
  end
end

Link to this section Summary

Functions

Call this macro from your projects Task module to declare an async function that, in a test environment, allows the async process to use the caller's Ecto connection.

Call this macro from your project's Task module to define an async_stream function that, in a test environment, allows the async process to use the caller's Ecto connection.

Link to this section Functions

Call this macro from your projects Task module to declare an async function that, in a test environment, allows the async process to use the caller's Ecto connection.

In other envs this delegates to the Elixir.Task.async/1 function.

Link to this macro

async_stream(repo)

View Source (macro)

Call this macro from your project's Task module to define an async_stream function that, in a test environment, allows the async process to use the caller's Ecto connection.

In other envs this delegates to the Elixir.Task.async_stream/3 function.