Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 12 for onceValue (0.2 sec)

  1. src/sync/oncefunc_test.go

    		b.ReportAllocs()
    		for i := 0; i < b.N; i++ {
    			if want, got := 42, onceValue(); want != got {
    				b.Fatalf("want %d, got %d", want, got)
    			}
    		}
    	})
    	b.Run("v=Local", func(b *testing.B) {
    		b.ReportAllocs()
    		onceValue := sync.OnceValue(func() int { return 42 })
    		for i := 0; i < b.N; i++ {
    			if want, got := 42, onceValue(); want != got {
    				b.Fatalf("want %d, got %d", want, got)
    			}
    		}
    	})
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Nov 21 17:31:33 UTC 2023
    - 6.9K bytes
    - Viewed (0)
  2. src/internal/syscall/windows/version_windows.go

    var SupportTCPInitialRTONoSYNRetransmissions = sync.OnceValue(func() bool {
    	major, _, build := version()
    	return major >= 10 && build >= 16299
    })
    
    // SupportUnixSocket indicates whether the current Windows version supports
    // Unix Domain Sockets.
    // The minimal requirement is Windows 10.0.17063.
    var SupportUnixSocket = sync.OnceValue(func() bool {
    	var size uint32
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Thu Mar 21 11:49:46 UTC 2024
    - 3.6K bytes
    - Viewed (0)
  3. src/sync/example_test.go

    			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.
    func ExampleOnceValue() {
    	once := sync.OnceValue(func() int {
    		sum := 0
    		for i := 0; i < 1000; i++ {
    			sum += i
    		}
    		fmt.Println("Computed once:", sum)
    		return sum
    	})
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Apr 23 17:45:47 UTC 2024
    - 2.2K bytes
    - Viewed (0)
  4. src/internal/syscall/unix/kernel_version_solaris.go

    	minor = parseNext()
    
    	return
    }
    
    // SupportSockNonblockCloexec tests if SOCK_NONBLOCK and SOCK_CLOEXEC are supported
    // for socket() system call, returns true if affirmative.
    var SupportSockNonblockCloexec = sync.OnceValue(func() bool {
    	// First test if socket() supports SOCK_NONBLOCK and SOCK_CLOEXEC directly.
    	s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, 0)
    	if err == nil {
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Mon Apr 15 03:10:07 UTC 2024
    - 3.1K bytes
    - Viewed (0)
  5. src/sync/oncefunc.go

    	}
    	return func() {
    		once.Do(g)
    		if !valid {
    			panic(p)
    		}
    	}
    }
    
    // OnceValue returns a function that invokes f only once and returns the value
    // returned by f. The returned function may be called concurrently.
    //
    // If f panics, the returned function will panic with the same value on every call.
    func OnceValue[T any](f func() T) func() T {
    	var (
    		once   Once
    		valid  bool
    		p      any
    		result T
    	)
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Nov 21 17:31:33 UTC 2023
    - 2K bytes
    - Viewed (0)
  6. src/internal/sysinfo/sysinfo.go

    // Package sysinfo implements high level hardware information gathering
    // that can be used for debugging or information purposes.
    package sysinfo
    
    import (
    	"internal/cpu"
    	"sync"
    )
    
    var CPUName = sync.OnceValue(func() string {
    	if name := cpu.Name(); name != "" {
    		return name
    	}
    
    	if name := osCPUInfoName(); name != "" {
    		return name
    	}
    
    	return ""
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue May 07 18:42:42 UTC 2024
    - 518 bytes
    - Viewed (0)
  7. src/internal/poll/copy_file_range_linux.go

    // Use of this source code is governed by a BSD-style
    // license that can be found in the LICENSE file.
    
    package poll
    
    import (
    	"internal/syscall/unix"
    	"sync"
    	"syscall"
    )
    
    var isKernelVersionGE53 = sync.OnceValue(func() bool {
    	major, minor := unix.KernelVersion()
    	// copy_file_range(2) is broken in various ways on kernels older than 5.3,
    	// see https://go.dev/issue/42400 and
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Thu Apr 04 17:40:10 UTC 2024
    - 3.9K bytes
    - Viewed (0)
  8. src/os/pidfd_linux.go

    	}
    	defer p.handleTransientRelease()
    
    	return convertESRCH(unix.PidFDSendSignal(handle, s))
    }
    
    func pidfdWorks() bool {
    	return checkPidfdOnce() == nil
    }
    
    var checkPidfdOnce = sync.OnceValue(checkPidfd)
    
    // checkPidfd checks whether all required pidfd-related syscalls work.
    // This consists of pidfd_open and pidfd_send_signal syscalls, and waitid
    // syscall with idtype of P_PIDFD.
    //
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Jun 11 18:08:44 UTC 2024
    - 4.2K bytes
    - Viewed (0)
  9. src/cmd/compile/internal/test/inl_test.go

    			// that the returned closure can be inlined into the caller of OnceFunc.
    			"OnceFunc",
    			"OnceFunc.func2", // The returned closure.
    			// TODO(austin): It would be good to check OnceValue and OnceValues,
    			// too, but currently they aren't reported because they have type
    			// parameters and aren't instantiated in sync.
    		},
    		"sync/atomic": {
    			// (*Bool).CompareAndSwap handled below.
    			"(*Bool).Load",
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Apr 09 04:07:57 UTC 2024
    - 10.7K bytes
    - Viewed (0)
  10. api/go1.21.txt

    pkg strings, func ContainsFunc(string, func(int32) bool) bool #54386
    pkg sync, func OnceFunc(func()) func() #56102
    pkg sync, func OnceValue[$0 interface{}](func() $0) func() $0 #56102
    pkg sync, func OnceValues[$0 interface{}, $1 interface{}](func() ($0, $1)) func() ($0, $1) #56102
    pkg syscall (freebsd-386-cgo), type SysProcAttr struct, Jail int #46259
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Mon Aug 07 09:39:17 UTC 2023
    - 25.6K bytes
    - Viewed (0)
Back to top