Resource

gears.async.Resource
See theResource companion object
trait Resource[+T]

A Resource wraps allocation to some asynchronously allocatable and releasable resource and grants access to it. It allows both structured access (similar to scala.util.Using) and unstructured allocation.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Abstract methods

def allocated(using Async): (T, Async ?=> Unit)

Allocate the resource and leak it. Use with caution. The programmer is responsible for closing the resource with the returned handle.

Allocate the resource and leak it. Use with caution. The programmer is responsible for closing the resource with the returned handle.

Attributes

Returns

the allocated access to the resource data as well as a handle to close it

Concrete methods

def flatMap[U](fn: T => Async ?=> Resource[U]): Resource[U]

Create a derived resource that creates a inner resource from the resource data. The inner resource will be acquired simultaneously, thus it can both transform the resource data and add a new cleanup action.

Create a derived resource that creates a inner resource from the resource data. The inner resource will be acquired simultaneously, thus it can both transform the resource data and add a new cleanup action.

Value parameters

fn

a function that creates an inner resource

Attributes

Returns

the transformed resource that provides the two-levels-in-one access

def map[U](fn: T => Async ?=> U): Resource[U]

Create a derived resource that inherits the close operation.

Create a derived resource that inherits the close operation.

Value parameters

fn

the function used to transform the resource data. It is only run on allocation/use.

Attributes

Returns

the transformed resource used to access the mapped resource data

def use[V](body: T => V)(using Async): V

Run a structured action on the resource. It is allocated and released automatically.

Run a structured action on the resource. It is allocated and released automatically.

Value parameters

body

the action to run on the resource

Attributes

Returns

the result of body