openclose

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package openclose provides a synchronization primitive (similar to a semaphore)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenClose

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

OpenClose represents a synchronization primitive (similar to a semaphore) that can be used to signal that an operation has started. All methods are safe to call from multiple goroutines.

func (*OpenClose) IsCloseRequested

func (oc *OpenClose) IsCloseRequested() bool

IsCloseRequested returns true if the OpenClose is requested to be closed.

func (*OpenClose) IsClosed

func (oc *OpenClose) IsClosed() bool

IsClosed returns true if the OpenClose is closed.

func (*OpenClose) Open

func (oc *OpenClose) Open(fn func()) (bool, func())

Open opens the OpenClose and returns a function that can be used to close it. If the OpenClose is already opened or closed, it returns false and a nil function. If fn is not nil, it will be called before the OpenClose is opened.

func (*OpenClose) RequestClose

func (oc *OpenClose) RequestClose(fn func()) bool

RequestClose requests that the OpenClose be closed and calls fn if close has not been requested. It will run fn even if the OpenClose is already closed from Open callback, but it was not requested to be closed.

func (*OpenClose) RequestCloseWait

func (oc *OpenClose) RequestCloseWait(fn func()) bool

RequestCloseWait requests that the OpenClose be closed and calls fn if close has not been requested. It will run fn even if the OpenClose is already closed from Open callback, but it was not requested to be closed. It waits until the Open callback is called and the OpenClose is closed.

Jump to

Keyboard shortcuts

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