mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
### Motivation: In many situations, for example continuous profiling with sampling profilers, it's important to distinguish between on- and off-CPU work. That's most easily done if there are clear function names/prefixes to grep for that are common places to just wait (off-CPU) and do no real work. In SwiftNIO those are chiefly three places: 1. The `EventLoops` waiting for work 2. `The NIOThreadPool` threads waiting for work 3. `EventLoopFuture.wait()` This patch makes sure that each of those will have a function with prefix `_blockingWaitFor` in the function name which is easily greppable. ### Modifications: - Create some non-inlinable functions with `_blockingWaitFor...` that just wait for `...`. ### Result: SwiftNIO makes operational excellence easier and your SRE team more happy.
36 lines
1.1 KiB
Swift
36 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2017-2024 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension IOResult where T: FixedWidthInteger {
|
|
var result: T {
|
|
switch self {
|
|
case .processed(let value):
|
|
return value
|
|
case .wouldBlock(_):
|
|
fatalError("cannot unwrap IOResult")
|
|
}
|
|
}
|
|
}
|
|
|
|
/// An result for an IO operation that was done on a non-blocking resource.
|
|
@usableFromInline
|
|
enum IOResult<T: Equatable>: Equatable {
|
|
|
|
/// Signals that the IO operation could not be completed as otherwise we would need to block.
|
|
case wouldBlock(T)
|
|
|
|
/// Signals that the IO operation was completed.
|
|
case processed(T)
|
|
}
|