Semaphore
public struct Semaphore
DispatchSemaphore
struct wrapper.
-
Creates new counting semaphore with an initial value. Passing zero for the value is useful for when two threads need to reconcile the completion of a particular event. Passing a value greater than zero is useful for managing a finite pool of resources, where the pool size is equal to the value.
Declaration
Swift
public init(poolSize: Int = 0)
Parameters
poolSize
The starting value for the semaphore. Passing a value less than zero will cause
nil
to be returned. -
Wait for a
continue
function call.Declaration
Swift
@discardableResult public func wait(_ timeout: DispatchTime = .distantFuture) -> DispatchTimeoutResult
Parameters
timeout
The timeout
DispatchTime
. Default is.distantFuture
.Return Value
Returns a
DispatchTimeoutResult
. -
This function returns non-zero if a thread is woken. Otherwise, zero is returned.
Declaration
Swift
@discardableResult public func `continue`() -> Int
Return Value
Returns non-zero if a thread is woken. Otherwise, zero is returned.