Skip to content

Commit

Permalink
Merge branch 'main' into jw-clientboot-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
weissi authored Nov 25, 2024
2 parents 9d59f71 + 6ba8f4f commit 6b290ee
Show file tree
Hide file tree
Showing 50 changed files with 1,032 additions and 373 deletions.
2 changes: 1 addition & 1 deletion Sources/NIOCore/ChannelInvoker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ extension ChannelOutboundInvoker {
public func close(mode: CloseMode = .all, file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<Void>
{
let promise = makePromise(file: file, line: line)
close(mode: mode, promise: promise)
self.close(mode: mode, promise: promise)
return promise.futureResult
}

Expand Down
19 changes: 18 additions & 1 deletion Sources/NIOCore/ChannelPipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
// Copyright (c) 2017-2024 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
Expand Down Expand Up @@ -2131,6 +2131,23 @@ extension ChannelHandlerContext {
self.writeAndFlush(data, promise: promise)
return promise.futureResult
}

/// Returns this `ChannelHandlerContext` as a `NIOLoopBound`, bound to `self.eventLoop`.
///
/// This is a shorthand for `NIOLoopBound(self, eventLoop: self.eventLoop)`.
///
/// Being able to capture `ChannelHandlerContext`s in `EventLoopFuture` callbacks is important in SwiftNIO programs.
/// Of course, this is not always safe because the `EventLoopFuture` callbacks may run on other threads. SwiftNIO
/// programmers therefore always had to manually arrange for those callbacks to run on the correct `EventLoop`
/// (i.e. `context.eventLoop`) which then made that construction safe.
///
/// Newer Swift versions contain a static feature to automatically detect data races which of course can't detect
/// the only _dynamically_ ``EventLoop`` a ``EventLoopFuture`` callback is running on. ``NIOLoopBound`` can be used
/// to prove to the compiler that this is safe and in case it is not, ``NIOLoopBound`` will trap at runtime. This is
/// therefore dynamically enforce the correct behaviour.
public var loopBound: NIOLoopBound<ChannelHandlerContext> {
NIOLoopBound(self, eventLoop: self.eventLoop)
}
}

@available(*, unavailable)
Expand Down
Loading

0 comments on commit 6b290ee

Please sign in to comment.