resource

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package resource provides some means to deal with resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClosableIOTransform

func ClosableIOTransform[A any](cioca Closable[io.IO[Closable[A]]]) (ioca io.IO[Closable[A]])

ClosableIOTransform transforms a closable of io closable to just io closable.

func Use

func Use[A any, B any](res Resource[A], f func(A) io.IO[B]) io.IO[B]

Use is a only way to access the resource instance. It guarantees that the resource instance will be closed after use regardless of the failure/success result.

Types

type Closable

type Closable[A any] struct {
	Value A
	Close func() io.IO[fun.Unit]
}

Closable is a value that is accompanied with the Close(). This is an internal structure that should not be used outside of the resource package.

func ClosableFlatMap

func ClosableFlatMap[A any, B any](ca Closable[A], f func(a A) Closable[B]) Closable[B]

ClosableFlatMap flatmaps the closable. Allows to construct have more than one resource in scope.

func ClosableMap

func ClosableMap[A any, B any](ra Closable[A], f func(a A) B) Closable[B]

ClosableMap is an internal function to map closable using the provided function.

type ClosableIO added in v0.1.8

type ClosableIO interface {
	Close() io.IOUnit
}

ClosableIO is a simple resource that implements Close method.

type Resource

type Resource[A any] io.IO[Closable[A]]

Resource[A] is an structure that can only be _used_ via Use. Unfortunately, it's not an interface, because interface methods do not support generics at the moment.

func BoundedExecutionContextResource added in v0.1.8

func BoundedExecutionContextResource(size int, queueLimit int) Resource[io.ExecutionContext]

BoundedExecutionContextResource returns a resource that is a bounded execution context.

func Fail added in v0.2.3

func Fail[A any](err error) Resource[A]

Fail creates a resource that will fail during acquisition.

func FlatMap

func FlatMap[A any, B any](ra Resource[A], f func(a A) Resource[B]) Resource[B]

FlatMap allows to add another resource to scope. Both will be released in reverse order.

func FromClosableIO added in v0.1.8

func FromClosableIO[A ClosableIO](ioa io.IO[A]) Resource[A]

FromClosableIO constructs a new resource from some value that itself supports method Close.

func Map

func Map[A any, B any](ra Resource[A], f func(a A) B) Resource[B]

Map maps the resource value using the provided conversion function.

func NewResource

func NewResource[A any](acquire io.IO[A], release func(A) io.IO[fun.Unit]) Resource[A]

NewResource constructs a resource given two functions - acquire and release.

func NewResourceFromIOClosable

func NewResourceFromIOClosable[A any](cl io.IO[Closable[A]]) Resource[A]

NewResourceFromIOClosable - is an internal function that constructs a resource from closable IO.

func UnbufferedChannel added in v0.1.0

func UnbufferedChannel[A any]() Resource[chan A]

UnbufferedChannel returns a resource that manages a channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL