-
-
Notifications
You must be signed in to change notification settings - Fork 17
Use Swift 6.2 Task.immediate for task creation to immediately start action #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Use Swift 6.2 Task.immediate for task creation to immediately start action #17
Conversation
|
Does it build against older Swift versions? |
I haven't thought about that, and you are right when using a Swift version below 6.2 it fails to compile with the error: |
|
With the latest commit I was able to build and run the demo app using Xcode 16.2.0 that is using Swift 6.0. |
|
It also builds on Swift 5.10 (tested just now). |
|
I've been reviewing the code, and I might find a potential issue. This makes few features of the library related to button events unreliable:
Sadly this could break current lib users behavior. I need to think this more through. |
|
This could be a solution, but I'm not sure for my 1AM reasoning. |
You're right, this Task.immediate seems to break the apis around the I am not seeing right now a simple solution to keep the existing behavior, while using |
Swift 6.2 added a new API to create a task: Task.immediate(name:priority:executorpreference:operation:), also described in SE-0472 Starting tasks synchronously from caller context.
Using this new api makes possible to remove the delay between the user gesture and the execution of the action, at least until an asynchronous operation is awaited.
Here what can be observed with this change on the demo project. With Task.immediate we prevent the loader to being shown as the reset button executes its action immediately.
Using.Task.immediate.creation.mov
Using.Task.creation.mov
Note: As this new API is only available on 26.0 version of various of operating systems, the old behaviour is kept when this API is not available.