nosync
import "github.com/gopherjs/gopherjs/nosync"
Types
type Map
Map is a concurrent map with amortized-constant-time loads, stores, and deletes. It is safe for multiple goroutines to call a Map's methods concurrently.
The zero Map is valid and empty.
A Map must not be copied after first use.
type Map struct {
// contains filtered or unexported fields
}func Delete(key any)
Delete deletes the value for a key.
func Load(key any) (value any, ok bool)
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 LoadOrStore(key, value any) (actual any, loaded bool)
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 Range(f func(key, value any) bool)
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.
Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.
func Store(key, value any)
Store sets the value for a key.
type Mutex
Mutex is a dummy which is non-blocking.
type Mutex struct {
// contains filtered or unexported fields
}func Lock()
Lock locks m. It is a run-time error if m is already locked.
func Unlock()
Unlock unlocks m. It is a run-time error if m is not locked.
type Once
Once is an object that will perform exactly one action.
type Once struct {
// contains filtered or unexported fields
}func Do(f func())
Do calls the function f if and only if Do is being called for the first time for this instance of Once. In other words, given
var once Onceif once.Do(f) is called multiple times, only the first call will invoke f, even if f has a different value in each invocation. A new instance of Once is required for each function to execute.
Do is intended for initialization that must be run exactly once. Since f is niladic, it may be necessary to use a function literal to capture the arguments to a function to be invoked by Do:
config.once.Do(func() { config.init(filename) })If f causes Do to be called, it will panic.
If f panics, Do considers it to have returned; future calls of Do return without calling f.
type Pool
A Pool is a set of temporary objects that may be individually saved and retrieved.
Any item stored in the Pool may be removed automatically at any time without notification. If the Pool holds the only reference when this happens, the item might be deallocated.
A Pool is safe for use by multiple goroutines simultaneously.
Pool's purpose is to cache allocated but unused items for later reuse, relieving pressure on the garbage collector. That is, it makes it easy to build efficient, thread-safe free lists. However, it is not suitable for all free lists.
An appropriate use of a Pool is to manage a group of temporary items silently shared among and potentially reused by concurrent independent clients of a package. Pool provides a way to amortize allocation overhead across many clients.
An example of good use of a Pool is in the fmt package, which maintains a dynamically-sized store of temporary output buffers. The store scales under load (when many goroutines are actively printing) and shrinks when quiescent.
On the other hand, a free list maintained as part of a short-lived object is not a suitable use for a Pool, since the overhead does not amortize well in that scenario. It is more efficient to have such objects implement their own free list.
type Pool struct {
New func() any
// contains filtered or unexported fields
}Fields
New func() any
func Get() any
Get selects an arbitrary item from the Pool, removes it from the Pool, and returns it to the caller. Get may choose to ignore the pool and treat it as empty. Callers should not assume any relation between values passed to Put and the values returned by Get.
If Get would otherwise return nil and p.New is non-nil, Get returns the result of calling p.New.
func Put(x any)
Put adds x to the pool.
type RWMutex
RWMutex is a dummy which is non-blocking.
type RWMutex struct {
// contains filtered or unexported fields
}func Lock()
Lock locks m for writing. It is a run-time error if rw is already locked for reading or writing.
func RLock()
RLock locks m for reading. It is a run-time error if rw is already locked for reading or writing.
func RUnlock()
RUnlock undoes a single RLock call; it does not affect other simultaneous readers. It is a run-time error if rw is not locked for reading.
func Unlock()
Unlock unlocks rw for writing. It is a run-time error if rw is not locked for writing.
type WaitGroup
WaitGroup is a dummy which is non-blocking.
type WaitGroup struct {
// contains filtered or unexported fields
}func Add(delta int)
Add adds delta, which may be negative, to the WaitGroup If the counter goes negative, Add panics.
func Done()
Done decrements the WaitGroup counter.
func WaitGroup) Wait()
Wait panics if the WaitGroup counter is not zero.
