Commit Graph
5 Commits
Author SHA1 Message Date
Cory BenfieldandGeorge Barnett f46998ce2d Make isolated execute on async testing eventloop actually run (#3116)
Motivation:

The isolated execute on async testing event loop wouldn't execute tasks
in the case of promise being nil

Modifications:

Rewrite the execute logic slightly.

Result:

Correct execution

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-02-18 19:03:24 +00:00
Rick Newton-Rogers 7789652b83 Add more methods to work with Isolated futures (#3117)
### Motivation:

Whilst working on the NIOHTTP1 strict concurrency work I encountered a
few gaps in the API where I needed isolated analogues of methods on
futures.

### Modifications:

* Add `makeSucceededIsolatedFuture`
* Add a new internal initializer for `EventLoopFuture` which does not
require the value to be Sendable for use in isolated contexts.
* Add a variant of `flatMapError` which can handle closures which return
isolated futures
* Add a `futureResult` computed property which allows us to avoid the
otherwise clumsy `future.nonIsolated().futureResult.assumeIsolated()`

### Result:

More ability to work with isolated futures.
2025-02-14 14:56:06 +00:00
Cory Benfield fd6eb16ae5 Ensure we test the isolated fallback methods (#3072)
Motivation

I'm about to change all our main event loops to use our new
customisation points. That's great, but it'll have the effect of
removing all the testing of our default implementations, which is not a
good idea. So let's add some more tests.

Modifications

Define a "fallback" event loop for testing the isolated methods.

Result

Reduced likelihood of regressions in future.
2025-01-20 16:09:52 +00:00
Cory Benfield 853619335d Improve coverage of isolated views (#3069)
Motivation:

We were only testing the isolated views on SelectableEventLoop. That was
fine when all the implementation was common, but it isn't going to be
anymore, so we should start having tests across all our EL kinds.

Modifications:

Refactor the tests to take their EL as an argument
Add support for ELs that need to be explicitly run 
Add tests for NIOAsyncTestingEL and EmbeddedEL

Result:

Better test coverage.
2025-01-17 14:15:35 +00:00
Cory Benfield 1e4fde1093 Add isolated views to EventLoop, Promise, and Future (#2969)
Motivation:

Users writing NIO code in a strict concurrency world often need to
interact with futures, promises, and event loops. The main interface to
these has strict sendability requirements, as it is possible the user is
doing so from outside the EventLoop that provides the isolation domain
for these types.

However, in many cases the user knows that they are on the isolation
domain in question. In that case, they need more capabilities. While
they can achieve their goals with NIOLoopBound today, it'd be nice if
they had a better option.

Modifications:

- Make EventLoop.Isolated public.
- Make EventLoopFuture.Isolated public.
- Make EventLoopPromise.Isolated public.
- Make all their relevant methods public.
- Move the runtime isolation check from the point of use to the point of
construction.
- Make the types non-Sendable to ensure that isolation check is
sufficient.
- Add unsafeUnchecked options to create these types when performance
matters and correctness is clear.
- Add tests for their behaviour.
- Update the documentation.

Result:

Writing safe code with promises, futures, and event loops is easier.
2024-12-16 14:20:01 +00:00