Replies: 4 comments 18 replies
-
Hello, @groue |
Beta Was this translation helpful? Give feedback.
-
Which apis should get an async version? The "Phase 1" is making progress in the dev/async branch. Those database access methods now have an
About the async version of I did not start thinking about how we can build an async sequence out of I'm even less sure how Which other apis should become async? |
Beta Was this translation helpful? Give feedback.
-
Pull request for Phase 1: #1079 Public announcement: GRDB: Async/await edition is looking for testers |
Beta Was this translation helpful? Give feedback.
-
GRDB 5.17.0 is out, with the "phase 1" of async/await, as framed by @Nekitosss. Future evolutions will be driven by feedback on this initial release. |
Beta Was this translation helpful? Give feedback.
-
New swift concurrency model consists from several parts. Two most valuable of them is synchronous-like execution flow (async await itself) and performance and safety improvements (prevention of priority inversion, much less context switches between threads via cooperative thread pool). So for proper adoption of whole swift concurrency idea we should consider several phases. Let's just describe them:
actor
synchronisation mechanism under the hood forAsyncDatabaseQueue
, separating async version of protocols from sync version.AsyncDatabasePool
. Phase 3 is currently not implementable because of lack of custom executors support.This discussion will be just about Phase 1. I will provide drafts, difficulties and possibilities for adoption. A little bit later I will create discussion for Phase 2 with more options and reasoning to show idea and take more feedback and thoughts from @groue and other folks.
Let's code!
Implementation of async await via continuation if pretty straightforward for any method. Just:
We have a problems with incorrect implementation of method overloading diffing just with async keyword. All problems described below happened only with protocols. When we use just concrete classes, everything works perfectly. I tried several approaches to workaround the issue and here is my notes:
1. The case from swift bug that is not working
We can't create tho methods in protocols diffing with just async keyword. Compilation fails.2. Workaround that works for methods with any parameters
But! We can just create protocol extension that wraps one of another protocol methods. This compiles successfully.3. But this not really work when we have generics
This still compiles without errors.But! We are facing problems from the call side when we start using generics. Compiler shows us warning
No 'async' operations occur within 'await' expression
when we callawait t.test(closure: { return 0 })
4. Lets apply next filthy workaround which looks like solves our problems again
Bring good old
@_disfavoredOverload
. This compiles without any warnings and errors.P.S. Everything tested with
Xcode Version 13.0 (13A233)
swift-driver version: 1.26.9 Apple Swift version 5.5 (swiftlang-1300.0.29.102 clang-1300.0.28.1)
Target: x86_64-apple-macosx12.0
Beta Was this translation helpful? Give feedback.
All reactions