waitop

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package waitop provides wait for executing asynchronous operation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyDoing indicates WaitOp is executing already.
	ErrAlreadyDoing = errors.New("already doing")

	// ErrTerminated indicates WaitOp have been closed without Fulfill() or
	// Rejected().
	ErrTerminated = errors.New("terminated")

	// ErrNotDoing indicates asynchronous operation is not started yet.
	ErrNotDoing = errors.New("not started")
)

Functions

This section is empty.

Types

type AsyncOp

type AsyncOp func() error

AsyncOp starts asynchronous operation. When AsyncOp is finished Fulfill() or Reject() should be called.

type WaitOp

type WaitOp struct {
	// contains filtered or unexported fields
}

WaitOp provides wait for exclusive asynchronous operation.

func New

func New() *WaitOp

New creates a WaitOp instance.

func (*WaitOp) Close

func (w *WaitOp) Close() error

Close closes WaitOp. When executing WaitOp is closed, it returns ErrTerminated.

func (*WaitOp) Do

func (w *WaitOp) Do(f AsyncOp) (interface{}, error)

Do starts asynchronous operation if it's not started yet. ErrAlreadyDoing and ErrTerminated will be retured.

func (*WaitOp) Fulfill

func (w *WaitOp) Fulfill(retval interface{}) error

Fulfill should be called with result value if asynchronous operation is finished successfully. When WaitOp is not started yet, this returns ErrNotDoing.

func (*WaitOp) Reject

func (w *WaitOp) Reject(err error) error

Reject should be called if asynchronous operation is failed. When WaitOp is not started yet, this returns ErrNotDoing.

Jump to

Keyboard shortcuts

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