NIOLoopBoundBox

NIOLoopBoundBox is an always-Sendable, reference-typed container allowing you access to value if and only if you are accessing it on the right EventLoop.

NIOLoopBound.swift:74
final class NIOLoopBoundBox<Value>

NIOLoopBoundBox is useful to transport a value of a non-Sendable type that needs to go from one place in your code to another where you (but not the compiler) know is on one and the same EventLoop. Usually this involves @Sendable closures. This type is safe because it verifies (using preconditionInEventLoop(file:line:)) that this is actually true.

A NIOLoopBoundBox can only be read from or written to when you are provably (through preconditionInEventLoop(file:line:)) on the EventLoop associated with the NIOLoopBoundBox. Accessing or constructing it from any other place will crash your program with a precondition as it would be undefined behaviour to do so.

If constructing a NIOLoopBoundBox with a value, it is also required for the program to already be on eventLoop but if you have a NIOLoopBoundBox that contains an Optional type, you may initialise it without a value whilst off the EventLoop by using makeEmptyBox(valueType:eventLoop:). Any read/write access to value afterwards will require you to be on eventLoop.