View Source Antikythera.Tmpdir (antikythera v0.5.1)

Summary

Functions

Creates a temporary directory which can be used as a working space for the passed function f.

Functions

Link to this function

make(context_or_epool_id, f)

View Source
@spec make(Antikythera.ExecutorPool.Id.t() | Antikythera.Context.t(), (Path.t() -> a)) ::
  a
when a: any()

Creates a temporary directory which can be used as a working space for the passed function f.

This function is basically intended for async jobs which processes large amount of data. For example, an async job that accumulates data into files and upload them to somewhere can utilize this function to obtain a temporary working space.

The temporary directory is created before f is invoked. When execution of f is finished (either successfully or by exception) the directory is automatically removed. The function returns the return value of f.

Nested calls to this function is not allowed. Instead you can freely make subdirectories of the temporary directory.

Example

Antikythera.Tmpdir.make(context, fn tmpdir ->
  path = Path.join(tmpdir, "foo")
  File.open(path, [:write], fn file ->
    IO.write(file, "some data 1")
    IO.write(file, "some data 2")
  end)
  upload_to_object_storage_service("object_key", path)
end)