Experimenting with async & await in Swift

  Рет қаралды 9,546

Vincent Pradeilles

Vincent Pradeilles

Күн бұрын

Пікірлер: 43
@v_pradeilles
@v_pradeilles 4 жыл бұрын
Did you find this preview useful? Are you planning on using async & await in your apps? Let me know in the comments 🚀
@operative3000
@operative3000 4 жыл бұрын
Do you have a version of this demo in French? Merci
@v_pradeilles
@v_pradeilles 4 жыл бұрын
@@operative3000 sorry for the moment I’m not planning to do videos in French
@ganeshpawartrekker
@ganeshpawartrekker 2 жыл бұрын
Thank you for sharing knowledge and I am impressed with the way you do it, by comparing old thing and then converting it with new concept makes it simple to understand otherwise teaching new concept directly without giving old way as reference makes it difficult to understand.
@kublaios
@kublaios 4 жыл бұрын
That's the second video of yours that I watched and both of them were very fruitful and distinct. Keep up the good work.
@zsoltb7003
@zsoltb7003 4 жыл бұрын
Thanks for taking the time Vincent. Very helpful!
@Devtherapy
@Devtherapy 4 жыл бұрын
Finally it is happening. I came to iOS and Swift world from C# and I always was missing async/await feature. Finally it will be easy to handle async code without callback hells
@DesperadoAH
@DesperadoAH 3 жыл бұрын
I love that you are explaining more advanced features and yet not released 👍, keep up the good work
@lukaszstocki6998
@lukaszstocki6998 4 жыл бұрын
Reminds me of "do syntax" in Haskell :) Very cool movie! Waiting for more!
@poluxsaurus1454
@poluxsaurus1454 4 жыл бұрын
Hi Vincent, two questions: 1) At 3:26 what keyboard shortcut are you using to get the trailing closure template? and 2) Does calling a function with @asyncHandler prevent blocking of the caller's thread and does that mean that it handles the call in another thread automatically?
@v_pradeilles
@v_pradeilles 4 жыл бұрын
1) I just pressed the return key 2) Great question! From what I understand, it will not block the caller's thread. I'm not sure on which queue/thread it gets called, I guess it might have something to do with the new addition "actor classes" to Swift, and I've yet to fully understand that concept.
@poluxsaurus1454
@poluxsaurus1454 4 жыл бұрын
@@v_pradeilles re 1) Oh right I didn't remember it would generate trailing closure syntax... thanks
@fredericadda
@fredericadda 4 жыл бұрын
Wow, super intéressant ! J’avais lu la description de l’évolution, mais c’était assez compliqué à comprendre. Là c’est très pédagogique, bravo!
@v_pradeilles
@v_pradeilles 4 жыл бұрын
Merci Fred !
@mickael93260
@mickael93260 4 жыл бұрын
Amazing! Depuis le temps qu'on l'attend sur Swift enfin il arrive
@andybezaire
@andybezaire 4 жыл бұрын
Thanks, your videos are the best. Could you do this same example but replace the pyramid of doom with a combine publisher? I would love to see that.
@v_pradeilles
@v_pradeilles 4 жыл бұрын
That might be an interesting idea for the future! But until then, here’s the short version answer: you want to use the method flatMap() to make sequential calls 🙂
@skanderbahri5274
@skanderbahri5274 3 жыл бұрын
Very helpful thank you
@bscheirman
@bscheirman 4 жыл бұрын
Really great introduction Vincent! 💯
@KK-pq6lu
@KK-pq6lu 3 жыл бұрын
Would be very valuable to have a version of this video with same example, but using the now released production version of XCode/Swift to see how it works without the old primitives.
@v_pradeilles
@v_pradeilles 3 жыл бұрын
Here it is 👉 Using async / await on iOS 13: everything you need to know! 🚀 kzbin.info/www/bejne/aHiki5ige7J0aMk
@filiplazov5895
@filiplazov5895 4 жыл бұрын
Great video thank you!
@appalling22
@appalling22 3 жыл бұрын
nice vid! One thing though - you keep saying the async function blocks, this isn't the case. The function does not block, it suspends, meaning that the thread that *was* executing the function becomes available for other work until the async task is complete. Async gets rid of callback hell and the pyramid of doom, but in this way it also allows concurrency.
@jabquintos
@jabquintos 4 жыл бұрын
Thank you, Vincent! 🙏
@croco049
@croco049 4 жыл бұрын
Nice intro to the feature ! I hope you didn't scare too many people with the unsafeContinuation API, as people have to keep in mind they'll likely never use this low level primitive in practice (stdlib and Foundation will already provided async API and that's what we'll actually use mostly) One question: how will we handle executing 2 async functions in parallel and waiting for the two at once (think Promise.zip)? Like, in your example, if I want the calls for both first and last name to be sent in parallel and print only when both have returned? (I'm pretty sure that it's something already taken into account in one of the various Concurrency SE proposals but haven't managed to keep track and follow it all, and idk if it's already part of the preview toolchains either?)
@v_pradeilles
@v_pradeilles 4 жыл бұрын
Great question! To handle concurrent execution, you can declare your calls using `async let`, then use the corresponding variables inside the same `await` expression and the compiler will handle the low-level background tasks.
@croco049
@croco049 4 жыл бұрын
@@v_pradeilles So async let firstName = await getFirstName(userId: userId) async let lastName = await getLastName(userId: userId) await print("Hello \(firstName) \(lastName)!") ?
@v_pradeilles
@v_pradeilles 4 жыл бұрын
@@croco049 precisely!
@christophescholly
@christophescholly 4 жыл бұрын
Very cool! 👍
@KautilyaSave
@KautilyaSave 3 жыл бұрын
Great video.
@palforsberg8432
@palforsberg8432 3 жыл бұрын
What if you want to retrieve first and last name in parallel? Is that possible?
@v_pradeilles
@v_pradeilles 3 жыл бұрын
You indeed can! All the details are in this video 👉 kzbin.info/www/bejne/f6ikgGNsjdlnhbs
@dmitriyobidin6049
@dmitriyobidin6049 4 жыл бұрын
Right now it looks kinda cumbersome... Especially considering that the beauty of async/await that you shouldn't think about low level details. And with that continuation thing it's just not worth it... Why they didn't make it like in js? Where if you make the function async, it's returning value automatically wrapped with Promise.
@w0mblemania
@w0mblemania 4 жыл бұрын
I agree that it looks janky and inelegant. This keyword and property wrapper proliferation has really gotten out of hand. Swift must look like a frankenstein language to new programmers.
@v_pradeilles
@v_pradeilles 4 жыл бұрын
Keep in mind that I used a development build of Swift. When the feature gets released, there will almost certainly be better primitives to create async functions than withUnsafeContinuation 😉
@appalling22
@appalling22 3 жыл бұрын
It is very similar to how it is in JS (and C# for that matter), it just looks complicated because Vincent's examples are wrapping code that uses completion handlers. The only time you will ever need to do that is when you're making legacy code async, which should be pretty rare. The rest of the time, your code will look basically identical to how it does in JS or C#.
@LouisCognault
@LouisCognault 4 жыл бұрын
Is there cancellation support?
@v_pradeilles
@v_pradeilles 4 жыл бұрын
I believe it’s indeed in the works. But of course it would require a bit more code, as then you’d need to deal more explicitly with the implicit background tasks.
@w0mblemania
@w0mblemania 4 жыл бұрын
Thanks for this. I don't like the way Swift is heading with this -- it's super-ugly code to write, and I'm not sure it's any better than the pyramid of doom -- but I'm grateful for the time you've taken to explain it all.
@majidbashir1797
@majidbashir1797 3 жыл бұрын
did someone remember flutter await and async keywords ? seems likes same functionality to me.
@v_pradeilles
@v_pradeilles 3 жыл бұрын
It's indeed a very similar functionality!
@trendz4422
@trendz4422 4 жыл бұрын
It seems like Swift makes more boilerplate code for this 😕
@donathmm3881
@donathmm3881 3 жыл бұрын
Cool
No more [weak self] 🤯 (special video for the 1,000 subscribers)
13:35
Vincent Pradeilles
Рет қаралды 7 М.
You hate DispatchQueue.main.async { } ? Good news, @MainActor killed it ☠️
11:51
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
RTX 5080 Performance Leaks!!!
9:47
Daniel Owen
Рет қаралды 40 М.
Async/Await in Swift | Comparison vs Closures and Combine Framework
19:59
Running tasks in parallel using async/await 🚀
6:41
Vincent Pradeilles
Рет қаралды 4 М.
3 MISTAKES to avoid when using Async / Await in Swift 😌
4:41
Vincent Pradeilles
Рет қаралды 12 М.
How to use async / await keywords in Swift  | Swift Concurrency #3
20:40
Swiftful Thinking
Рет қаралды 29 М.
Using async/await in SwiftUI
15:14
Peter Friese
Рет қаралды 4,1 М.
Don't write this code! (this local variable is really bad 🫣)
3:24
Vincent Pradeilles
Рет қаралды 4,2 М.
Responder chain & Hit testing | SWIFT
15:01
Swift Magic
Рет қаралды 8 М.
5 Hidden Windows Features You Should Be Using in 2025!
8:05
Kevin Stratvert
Рет қаралды 125 М.
Here's the ULTIMATE tip to find memory leaks in Xcode!
5:41
Vincent Pradeilles
Рет қаралды 15 М.
Making of Marble in Factory #shorts #ashortaday #indianstreetfood
0:59
Indian Food Vlogs
Рет қаралды 6 МЛН
ПЛЮСЫ и МИНУСЫ 1 и 2 смены в школе 🔥
0:39
Никита Удановский
Рет қаралды 3,5 МЛН
НИКОГДА не иди на сделку с сестрой!
0:11
Даша Боровик
Рет қаралды 729 М.