Documentation
¶
Index ¶
- Constants
- Variables
- func InitPool(cap int)
- func Recycle(p Promise)
- type AbstractPromise
- func (p *AbstractPromise) Close()
- func (p *AbstractPromise) Deadline() (time.Time, bool)
- func (p *AbstractPromise) Error() error
- func (p *AbstractPromise) IsResolved() bool
- func (p *AbstractPromise) OnCreateTimerLocked(*time.Timer)
- func (p *AbstractPromise) Options() interface{}
- func (p *AbstractPromise) Reset()
- func (p *AbstractPromise) ResetWithOptions(opts interface{})
- func (p *AbstractPromise) ResolveRets(rets ...interface{}) bool
- func (p *AbstractPromise) ResolvedAt() time.Time
- func (p *AbstractPromise) Result() (interface{}, error)
- func (p *AbstractPromise) SetProvider(provider PromiseProvider)
- func (p *AbstractPromise) SetTimeout(timeout time.Duration)
- func (p *AbstractPromise) TimeoutC(timeouts ...time.Duration) (<-chan time.Time, error)
- func (p *AbstractPromise) Value() interface{}
- type ChannelPromise
- func (p *ChannelPromise) Lock()
- func (p *ChannelPromise) Reset()
- func (p *ChannelPromise) ResetWithOptions(opts interface{})
- func (p *ChannelPromise) Resolve(rets ...interface{}) (Promise, error)
- func (p *ChannelPromise) Timeout(timeouts ...time.Duration) error
- func (p *ChannelPromise) Unlock()
- func (p *ChannelPromise) Wait()
- type Promise
- type PromiseProvider
- type SyncPromise
- func (p *SyncPromise) Lock()
- func (p *SyncPromise) OnCreateTimerLocked(timer *time.Timer)
- func (p *SyncPromise) Reset()
- func (p *SyncPromise) ResetWithOptions(opts interface{})
- func (p *SyncPromise) Resolve(rets ...interface{}) (Promise, error)
- func (p *SyncPromise) Timeout(timeouts ...time.Duration) error
- func (p *SyncPromise) Unlock()
- func (p *SyncPromise) Wait()
- type WaitGroupPromise
- func (p *WaitGroupPromise) Lock()
- func (p *WaitGroupPromise) Reset()
- func (p *WaitGroupPromise) ResetWithOptions(opts interface{})
- func (p *WaitGroupPromise) Resolve(rets ...interface{}) (Promise, error)
- func (p *WaitGroupPromise) Timeout(timeouts ...time.Duration) error
- func (p *WaitGroupPromise) Unlock()
- func (p *WaitGroupPromise) Wait()
Constants ¶
View Source
const (
PromiseInit = int64(0)
)
Variables ¶
View Source
var ( ErrResolved = errors.New("resolved already") ErrTimeoutNoSet = errors.New("timeout not set") ErrTimeout = errors.New("timeout") ErrNotImplemented = errors.New("not implemented") ErrReset = errors.New("promise reset") // OnNewPromise offers a default implementation to instancize a new Promise for the PromisePool. OnNewPromise = func() Promise { return NewWaitGroupPromise() } // PromisePool offer a default pool to reused the Promises on calling NewPromise. // The default implmentation offers no pooling, call InitPool to setup a pool. PromisePool sync.Pool[Promise] = &sync.NilPool[Promise]{New: OnNewPromise} )
Functions ¶
Types ¶
type AbstractPromise ¶
type AbstractPromise struct {
// contains filtered or unexported fields
}
func (*AbstractPromise) Close ¶
func (p *AbstractPromise) Close()
func (*AbstractPromise) Error ¶
func (p *AbstractPromise) Error() error
func (*AbstractPromise) IsResolved ¶
func (p *AbstractPromise) IsResolved() bool
func (*AbstractPromise) OnCreateTimerLocked ¶
func (p *AbstractPromise) OnCreateTimerLocked(*time.Timer)
func (*AbstractPromise) Options ¶
func (p *AbstractPromise) Options() interface{}
func (*AbstractPromise) Reset ¶
func (p *AbstractPromise) Reset()
func (*AbstractPromise) ResetWithOptions ¶
func (p *AbstractPromise) ResetWithOptions(opts interface{})
func (*AbstractPromise) ResolveRets ¶
func (p *AbstractPromise) ResolveRets(rets ...interface{}) bool
func (*AbstractPromise) ResolvedAt ¶
func (p *AbstractPromise) ResolvedAt() time.Time
func (*AbstractPromise) Result ¶
func (p *AbstractPromise) Result() (interface{}, error)
func (*AbstractPromise) SetProvider ¶
func (p *AbstractPromise) SetProvider(provider PromiseProvider)
func (*AbstractPromise) SetTimeout ¶
func (p *AbstractPromise) SetTimeout(timeout time.Duration)
func (*AbstractPromise) Value ¶
func (p *AbstractPromise) Value() interface{}
type ChannelPromise ¶
type ChannelPromise struct {
AbstractPromise
// contains filtered or unexported fields
}
func NewChannelPromise ¶
func NewChannelPromise() *ChannelPromise
func NewChannelPromiseWithOptions ¶
func NewChannelPromiseWithOptions(opts interface{}) *ChannelPromise
func ResolvedChannel ¶
func ResolvedChannel(rets ...interface{}) *ChannelPromise
func (*ChannelPromise) Lock ¶
func (p *ChannelPromise) Lock()
func (*ChannelPromise) Reset ¶
func (p *ChannelPromise) Reset()
func (*ChannelPromise) ResetWithOptions ¶
func (p *ChannelPromise) ResetWithOptions(opts interface{})
func (*ChannelPromise) Resolve ¶
func (p *ChannelPromise) Resolve(rets ...interface{}) (Promise, error)
func (*ChannelPromise) Unlock ¶
func (p *ChannelPromise) Unlock()
type Promise ¶
type Promise interface {
// Reset Reset promise
Reset()
// ResetWithOptions Reset promise will options
ResetWithOptions(interface{})
// Close Close the promise
Close()
// IsResolved If the promise is resolved
IsResolved() bool
// Get the time the promise last resolved. time.Time{} if the promise is unresolved.
ResolvedAt() time.Time
// Resolve Resolve the promise with value or (value, error)
Resolve(...interface{}) (Promise, error)
// Options Get options
Options() interface{}
// Value Get resolved value
Value() interface{}
// Result Helper function to get (value, error)
Result() (interface{}, error)
// Error Get last error on resolving
Error() error
// SetTimeout Set how long the promise should timeout.
SetTimeout(time.Duration)
// Deadline returns the deadline if timeout is set.
Deadline() (time.Time, bool)
// Timeout returns ErrTimeout if timeout, or ErrTimeoutNoSet if the timeout not set.
Timeout(timeout ...time.Duration) error
// TimeoutC returns a channel that is closed when the promise timeout.
TimeoutC(timeout ...time.Duration) (<-chan time.Time, error)
}
func NewPromise ¶
func NewPromise() (p Promise)
NewPromise returns a new promise provided by the pool.
func NewPromiseWithOptions ¶
func NewPromiseWithOptions(opts interface{}) Promise
NewPromise returns a new promise with options provided by the pool.
type PromiseProvider ¶
type SyncPromise ¶
type SyncPromise struct {
AbstractPromise
// contains filtered or unexported fields
}
func NewSyncPromise ¶
func NewSyncPromise() *SyncPromise
func NewSyncPromiseWithOptions ¶
func NewSyncPromiseWithOptions(opts interface{}) *SyncPromise
func ResolvedSync ¶
func ResolvedSync(rets ...interface{}) *SyncPromise
func (*SyncPromise) Lock ¶
func (p *SyncPromise) Lock()
func (*SyncPromise) OnCreateTimerLocked ¶
func (p *SyncPromise) OnCreateTimerLocked(timer *time.Timer)
func (*SyncPromise) Reset ¶
func (p *SyncPromise) Reset()
func (*SyncPromise) ResetWithOptions ¶
func (p *SyncPromise) ResetWithOptions(opts interface{})
func (*SyncPromise) Resolve ¶
func (p *SyncPromise) Resolve(rets ...interface{}) (Promise, error)
func (*SyncPromise) Unlock ¶
func (p *SyncPromise) Unlock()
type WaitGroupPromise ¶
type WaitGroupPromise struct {
AbstractPromise
// contains filtered or unexported fields
}
func NewWaitGroupPromise ¶
func NewWaitGroupPromise() *WaitGroupPromise
func NewWaitGroupPromiseWithOptions ¶
func NewWaitGroupPromiseWithOptions(opts interface{}) *WaitGroupPromise
func ResolvedWaitGroup ¶
func ResolvedWaitGroup(rets ...interface{}) *WaitGroupPromise
func (*WaitGroupPromise) Lock ¶
func (p *WaitGroupPromise) Lock()
func (*WaitGroupPromise) Reset ¶
func (p *WaitGroupPromise) Reset()
func (*WaitGroupPromise) ResetWithOptions ¶
func (p *WaitGroupPromise) ResetWithOptions(opts interface{})
func (*WaitGroupPromise) Resolve ¶
func (p *WaitGroupPromise) Resolve(rets ...interface{}) (Promise, error)
func (*WaitGroupPromise) Timeout ¶
func (p *WaitGroupPromise) Timeout(timeouts ...time.Duration) error
func (*WaitGroupPromise) Unlock ¶
func (p *WaitGroupPromise) Unlock()
Click to show internal directories.
Click to hide internal directories.