package async
import "fyne.io/fyne/v2/internal/async"
Package async provides unbounded channel and queue structures that are designed for caching unlimited number of a concrete type. For better performance, a given type should be less or euqal than 16 bytes.
The difference of an unbounded channel or queue is that unbounde channels can utilize select and channel semantics, whereas queue cannot. A user of this package should balance this tradeoff. For instance, an unbounded channel can provide zero waiting cost when trying to receiving an object when the receiving select statement has a default case, and a queue can only receive the object with a time amount of time, but depending on the number of queue item producer, the receiving time may increase accordingly.
Delicate dance: One must aware that an unbounded channel may lead to OOM when the consuming speed of the buffer is lower than the producing speed constantly. However, such a channel may be fairly used for event delivering if the consumer of the channel consumes the incoming forever, such as even processing.
Index ¶
- func EnsureMain(fn func())
- func EnsureNotMain(fn func())
- func IsMainGoroutine() bool
- func SetMainGoroutine()
- type CanvasObjectQueue
- func NewCanvasObjectQueue() *CanvasObjectQueue
- func (q *CanvasObjectQueue) In(v fyne.CanvasObject)
- func (q *CanvasObjectQueue) Len() uint64
- func (q *CanvasObjectQueue) Out() fyne.CanvasObject
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Len() (count int)
- func (m *Map[K, V]) Load(key K) (value V, ok bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m *Map[K, V]) Range(f func(key K, value V) bool)
- func (m *Map[K, V]) Store(key K, value V)
- type Pool
- type UnboundedChan
- func NewUnboundedChan[T any]() *UnboundedChan[T]
- func (ch *UnboundedChan[T]) Close()
- func (ch *UnboundedChan[T]) In() chan<- T
- func (ch *UnboundedChan[T]) Out() <-chan T
- type UnboundedStructChan
Functions ¶
func EnsureMain ¶
func EnsureMain(fn func())
EnsureMain is part of our thread transition and makes sure that the passed function runs on main. If the context is main or the transition has been disabled this will blindly run. Otherwise, an error will be logged and the function will be called on the main goroutine.
This will be removed later and should never be public
func EnsureNotMain ¶
func EnsureNotMain(fn func())
EnsureNotMain is part of our thread transition and makes sure that the passed function runs off main. If the context is running on a goroutine or the transition has been disabled this will blindly run. Otherwise, an error will be logged and the function will be called on a new goroutine.
This will be removed later and should never be public
func IsMainGoroutine ¶
func IsMainGoroutine() bool
IsMainGoroutine returns true if it is called from the main goroutine, false otherwise.
func SetMainGoroutine ¶
func SetMainGoroutine()
Types ¶
type CanvasObjectQueue ¶
type CanvasObjectQueue struct {
// contains filtered or unexported fields
}
CanvasObjectQueue implements lock-free FIFO freelist based queue.
Reference: https://dl.acm.org/citation.cfm?doid=248052.248106
func NewCanvasObjectQueue ¶
func NewCanvasObjectQueue() *CanvasObjectQueue
NewCanvasObjectQueue returns a queue for caching values.
func (*CanvasObjectQueue) In ¶
func (q *CanvasObjectQueue) In(v fyne.CanvasObject)
In puts the given value at the tail of the queue.
func (*CanvasObjectQueue) Len ¶
func (q *CanvasObjectQueue) Len() uint64
Len returns the length of the queue.
func (*CanvasObjectQueue) Out ¶
func (q *CanvasObjectQueue) Out() fyne.CanvasObject
Out removes and returns the value at the head of the queue. It returns nil if the queue is empty.
type Map ¶
Map is a generic wrapper around sync.Map.
func (*Map[K, V]) Clear ¶
func (m *Map[K, V]) Clear()
Clear deletes all the entries, resulting in an empty Map.
func (*Map[K, V]) Delete ¶
func (m *Map[K, V]) Delete(key K)
Delete deletes the value for a key.
func (*Map[K, V]) Len ¶
Len returns the length of the map. It is O(n) over the number of items.
func (*Map[K, V]) Load ¶
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*Map[K, V]) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
func (*Map[K, V]) Store ¶
func (m *Map[K, V]) Store(key K, value V)
Store sets the value for a key.
type Pool ¶
type Pool[T any] struct { // New specifies a function to generate // a value when Get would otherwise return the zero value of T. New func() T // contains filtered or unexported fields }
Pool is the generic version of sync.Pool.
func (*Pool[T]) Get ¶
func (p *Pool[T]) Get() T
Get selects an arbitrary item from the Pool, removes it from the Pool, and returns it to the caller.
func (*Pool[T]) Put ¶
func (p *Pool[T]) Put(x T)
Put adds x to the pool.
type UnboundedChan ¶
type UnboundedChan[T any] struct { // contains filtered or unexported fields }
UnboundedChan is a channel with an unbounded buffer for caching Func objects. A channel must be closed via Close method.
func NewUnboundedChan ¶
func NewUnboundedChan[T any]() *UnboundedChan[T]
NewUnboundedChan returns a unbounded channel with unlimited capacity.
func (*UnboundedChan[T]) Close ¶
func (ch *UnboundedChan[T]) Close()
Close closes the channel.
func (*UnboundedChan[T]) In ¶
func (ch *UnboundedChan[T]) In() chan<- T
In returns the send channel of the given channel, which can be used to send values to the channel.
func (*UnboundedChan[T]) Out ¶
func (ch *UnboundedChan[T]) Out() <-chan T
Out returns the receive channel of the given channel, which can be used to receive values from the channel.
type UnboundedStructChan ¶
type UnboundedStructChan struct {
// contains filtered or unexported fields
}
UnboundedStructChan is a channel with an unbounded buffer for caching struct{} objects. This implementation is a specialized version that optimizes for struct{} objects than other types. A channel must be closed via Close method.
func NewUnboundedStructChan ¶
func NewUnboundedStructChan() *UnboundedStructChan
NewUnboundedStructChan returns a unbounded channel with unlimited capacity.
func (*UnboundedStructChan) Close ¶
func (ch *UnboundedStructChan) Close()
Close closes the channel.
func (*UnboundedStructChan) In ¶
func (ch *UnboundedStructChan) In() chan<- struct{}
In returns a send-only channel that can be used to send values to the channel.
func (*UnboundedStructChan) Out ¶
func (ch *UnboundedStructChan) Out() <-chan struct{}
Out returns a receive-only channel that can be used to receive values from the channel.
Source Files ¶
chan.go chan_struct.go doc.go goroutine.go goroutine_desktop.go map.go map_clear_go1.23.go pool.go queue_canvasobject.go
- Version
- v2.6.0-beta1
- Published
- Mar 7, 2025
- Platform
- darwin/amd64
- Imports
- 7 packages
- Last checked
- 1 hour ago –
Tools for package owners.