Cleaned up some stuff formatting, simplified pointer operations, and added a concurrent test
A simple thread safe replacement for Dispatch Once and pthread_once for Swift.
Update your Package.swift to include the appropriate dependency below:
Package.swift
.package(name: "Once", "https://github.com/bscothern/Once.git", from: "1.4.0")
.package(url: "https://github.com/bscothern/Once.git", from: "1.3.2")
Include this line in your Cartfile:
Cartfile
github "bscothern/Once"
import Once let once = Once() func foo() { once.runOnce { // Do stuff that should only execute the first time foo() is called. } // Do stuff }
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Once
A simple thread safe replacement for Dispatch Once and pthread_once for Swift.
Swift Package Manager
Update your
Package.swift
to include the appropriate dependency below:Swift 5.2+
Swift 4.0-5.1
Carthage Usage
Include this line in your
Cartfile
:Usage