Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 2,656 for ONCE (0.03 sec)

  1. src/sync/once.go

    // first time for this instance of [Once]. In other words, given
    //
    //	var once Once
    //
    // if 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
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Fri Jun 07 21:14:51 UTC 2024
    - 2.5K bytes
    - Viewed (0)
  2. src/sync/once_test.go

    		t.Errorf("once failed outside run: %d is not 1", *o)
    	}
    }
    
    func TestOncePanic(t *testing.T) {
    	var once Once
    	func() {
    		defer func() {
    			if r := recover(); r == nil {
    				t.Fatalf("Once.Do did not panic")
    			}
    		}()
    		once.Do(func() {
    			panic("failed")
    		})
    	}()
    
    	once.Do(func() {
    		t.Fatalf("Once.Do called twice")
    	})
    }
    
    func BenchmarkOnce(b *testing.B) {
    	var once Once
    	f := func() {}
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Sep 16 21:22:33 UTC 2014
    - 1.1K bytes
    - Viewed (0)
  3. src/sync/oncefunc.go

    package sync
    
    // OnceFunc returns a function that invokes f only once. The returned function
    // may be called concurrently.
    //
    // If f panics, the returned function will panic with the same value on every call.
    func OnceFunc(f func()) func() {
    	var (
    		once  Once
    		valid bool
    		p     any
    	)
    	// Construct the inner closure just once to reduce costs on the fast path.
    	g := func() {
    		defer func() {
    			p = recover()
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Nov 21 17:31:33 UTC 2023
    - 2K bytes
    - Viewed (0)
  4. src/sync/example_test.go

    }
    
    func ExampleOnce() {
    	var once sync.Once
    	onceBody := func() {
    		fmt.Println("Only once")
    	}
    	done := make(chan bool)
    	for i := 0; i < 10; i++ {
    		go func() {
    			once.Do(onceBody)
    			done <- true
    		}()
    	}
    	for i := 0; i < 10; i++ {
    		<-done
    	}
    	// Output:
    	// Only once
    }
    
    // This example uses OnceValue to perform an "expensive" computation just once,
    // even when used concurrently.
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Apr 23 17:45:47 UTC 2024
    - 2.2K bytes
    - Viewed (0)
  5. src/go/doc/comment/testdata/list2.txt

    -- input --
    Text.
     1. Uno
       2) Dos
     3. Tres
       5. Cinco
     7. Siete
       11. Once
     12. Doce
     13. Trece.
    
    -- gofmt --
    Text.
     1. Uno
     2. Dos
     3. Tres
     5. Cinco
     7. Siete
     11. Once
     12. Doce
     13. Trece.
    
    -- text --
    Text.
     1. Uno
     2. Dos
     3. Tres
     5. Cinco
     7. Siete
     11. Once
     12. Doce
     13. Trece.
    
    -- markdown --
    Text.
    
     1. Uno
     2. Dos
     3. Tres
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Mon Apr 11 16:31:48 UTC 2022
    - 529 bytes
    - Viewed (0)
  6. pkg/util/interrupt/interrupt.go

    // to a Run method), even in the presence of process termination. It guarantees exactly once
    // invocation of the provided notify functions.
    type Handler struct {
    	notify []func()
    	final  func(os.Signal)
    	once   sync.Once
    }
    
    // New creates a new handler that guarantees all notify functions are run after the critical
    Registered: Sat Jun 15 01:39:40 UTC 2024
    - Last Modified: Mon Jan 16 09:22:35 UTC 2023
    - 2.7K bytes
    - Viewed (0)
  7. test/inline_sync.go

    	// the Lock fast path should be inlined
    	mutex.Lock() // ERROR "inlining call to sync\.\(\*Mutex\)\.Lock"
    }
    
    var once *sync.Once
    
    func small7() { // ERROR "can inline small7"
    	// the Do fast path should be inlined
    	once.Do(small5) // ERROR "inlining call to sync\.\(\*Once\)\.Do" "inlining call to atomic\.\(\*Uint32\)\.Load"
    }
    
    var rwmutex *sync.RWMutex
    
    func small8() { // ERROR "can inline small8"
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Fri Oct 06 21:01:50 UTC 2023
    - 1.6K bytes
    - Viewed (0)
  8. test/fixedbugs/issue49143.dir/a.go

    	batch *LoaderBatch[K, R]
    }
    
    func (l *Loader[K, R]) Load() error {
    	l.batch.f()
    	return nil
    }
    
    type LoaderBatch[K comparable, R any] struct {
    	once    *sync.Once
    }
    
    func (b *LoaderBatch[K, R]) f() {
    	b.once.Do(func() {})
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Wed Oct 27 05:33:58 UTC 2021
    - 451 bytes
    - Viewed (0)
  9. test/atomicload.go

    // Use of this source code is governed by a BSD-style
    // license that can be found in the LICENSE file.
    
    // Check that we do loads exactly once. The SSA backend
    // once tried to do the load in f twice, once sign extended
    // and once zero extended.  This can cause problems in
    // racy code, particularly sync/mutex.
    
    package main
    
    func f(p *byte) bool {
    	x := *p
    	a := int64(int8(x))
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Thu Mar 17 04:20:02 UTC 2016
    - 798 bytes
    - Viewed (0)
  10. staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/testing/openapi3.go

    package testing
    
    import (
    	"os"
    	"sync"
    
    	"k8s.io/kube-openapi/pkg/spec3"
    )
    
    type OpenAPIV3Getter struct {
    	Path      string
    	once      sync.Once
    	bytes     []byte
    	openapiv3 spec3.OpenAPI
    }
    
    func (f *OpenAPIV3Getter) SchemaBytesOrDie() []byte {
    	f.once.Do(func() {
    		_, err := os.Stat(f.Path)
    		if err != nil {
    			panic(err)
    		}
    		spec, err := os.ReadFile(f.Path)
    		if err != nil {
    			panic(err)
    Registered: Sat Jun 15 01:39:40 UTC 2024
    - Last Modified: Tue Oct 31 16:45:45 UTC 2023
    - 1.3K bytes
    - Viewed (0)
Back to top