Asynchronous programming with operations in Swift, Antoine van der Lee (English)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right hello everyone it's kind of strange I'm sitting here all alone in my living room all kinds of things can go wrong I certainly need to do shoutouts to do my friends who are also listening to face it I don't know you know it like normally when you speak you get like feedback from the audience and now I said seriously have no feedback the only thing I see is my slide but I'm pretty sure you all follow this and I can do whatever whatever is needed to teach you everything about asynchronous programming with operations in Swift I hope you're all fine the coronavirus is kind of taking over the world but there's never enough reason to go and learn more about Swift so let's say let's make the best out of it and see whether we can whether we can do this remotely so I want to start with a with a short introduction I'm going to talk about asynchronous programming with operations in Swift which we do quite a lot at we transfer and this is a short video you're a developer and you've just spent two weeks or maybe a little bit longer writing this amazing app and what is your dream your dream is to get it in front of every iPhone user and hopefully they love it and buy it right that's not possible today developers don't most developers don't have those kinds of resources even the big developers would have a hard time getting their app in front of every iPhone user well we're gonna solve that problem for every developer big to small and the way we're gonna do it is what we call the app store I hope this was a bit well doable to follow the sound came from my macbook but yeah nobody I would ask you like what is the year of this presentation I'll give you a sec to think about it and maybe you know but this was the year of the iPhone 3G this is quite quite a while ago in fact it's kind of funny if you think that this was Xcode at that time can you know imagine building an app with this this this UI it's pretty very pretty basic and it's far from what we have today literally enough this was me in the same here and we're talking about 2008 yeah that's like 12 years ago but that year we already could work with operations it's Swift this is the documentation from Apple and as you can see I always to introduce the first operation class and if you think about this class for over the years it wasn't always visible to everyone and it wasn't used by everyone and I want to kind of convince you and it all started for me with this of adopt up DC session from 2015 which I can can highly recommend it goes over NS operations in an advanced usage and they use the the depth of the see application because the fact is that the whole depth of DC app is built with operations and it might go a bit too far in the sense that they also use it for UI stuff and and and like validating whether a user is locked in before doing a certain operation but it does show the power of operations and how you can use it this the collector by wetransfer app which I'm working on a day-to-day basis and this is heavily built on operations I remember us deciding three years ago what the what to use as her main structure and we slowly started to build more of more operations and in fact right now we have 48 operations and I have to say I created two again today so it's actually already more but yeah it's paying off for us and for us it really works and we basically see an operation as a solution for writing asynchronous code yeah that's responsible for a single part but as well really testable and I want to show you a bit more about that and hopefully I can convince you that this is the next cool what kind of old thing but why why my operations well let me show you a few a few few reasons operations really are suitable for writing a single responsible code and with that I mean that your class is only responsible for a single thing for example we have a Content import operation which only does the importing of the content and we have a complete upload operation which is only doing the upload part and a great thing is because you have the isolated code you can also easy write tests or at least it makes it a bit more isolated so you don't have a really big test class as well then there is a great benefit of chaining operations together so here we have an import operation and and upload operation and eventually we set a dependency between both so what we say here is the upload operation can only start after the import operation is finished not it is that you can reuse operations so we have the upload content operation as we introduced before and we can use it after importing content but as well I have two copying content this makes it possible to write code once and reuse it in multiple places and easily chain it all together this can be a huge benefit especially in a bigger codebase also a great benefit as I showed before it's part of foundation it's to develop an apple and it's an API which is available since I always to which makes it quite mature it's been tested it's being used quite a lot yeah you can you can build on that but three years ago when we decided for this I remember myself also asking my colleagues like why not importing our X myth or maybe today if you make the decision today why wouldn't you input combined instead and the these two frameworks could be a great solution for asynchronous program and that's what all right so I can imagine you have this thought like why should I go for operations this is one of the reasons I would say go for operations over over a framework like combine it can be quite hard to debug it's obviously not always the case but it it's definitely a reason to think it through and whether you should really use combined as your core foundation in the app with rx Swift you're introducing an external dependency it's also third-party so it's probably likely that they need to do some updates or X 50 is well maintained so it's really good good framework to use however it's still like it's not part of foundation right so that's that's the main point I want to make here and then there is the case of combine where your deployment target needs to be a 13 and up and this is for for now something you have to take think about in a year or two this decision might be different but for now at least if you want to use operations you can use and support all the iOS versions available today of course you could work with the availability API but then you still have to maintain more code than than you would do with operations and even if you do these kind of generic codes aren't as readable for everyone and we will write some generic codes they run as well with operations but uh yeah I just wanted to show that it can be quite complicated so we now know why you should use operations and you know that collect is heavily built on operations I'm going to do a live coding session so we're in a live stream in a life environment with all things that go wrong and we're also going to do live coding so yeah bear with me you know way I'm going to go over the basics and I will also show you how we use operations in collect so I created this display but I think I will try to put it online as well previously when I did this presentation it was highly requested as well so let's see if we can do that so yeah let's let's start with the basics kind of be better if I keep it in the middle only yeah okay so we start with the operation queue and the operation queue is a high level implementation of today's pet queue and what it basically allows us to add operations to it and it gives you extra controls like cancellation and sending a maximum of concurrent operations which basically means that at a certain moment at maximum you can only be run a certain amount of operations at the same time the operation queue works with operations formerly known as NS operations and they basically are a high level implementation of this block and they are great for running long run any tasks but the real power is in the sub classing of operations this is the the very basic implementation we we have a block operation which basically execute a simple closure and you could set a completion block to any operation you have so I can run this code and we can see that its first executed and then it completed the operation and just like we bring to that this is quite basic so I think this is a still photo bubble then there is also a shorter version of a block operation as you can see here and if we can ruin that you can see that it's basically executing as well this however does not allow you to set the completion book but yeah it's just good to know that these api's exist then there is the order of execution and the operation queue basically runs operations in the order that they are added so here we add operations first the background operation and then use the triggered operation and notice that in this example we use the wait until finish as well which basically says clock this or block this thread on which we're calling this this method and wait to both operations are finished so every renders we see that the background operation is finished and after that the use of triggered operation as well however we have the user triggered operation and it's in general best practice to make sure that those use it wicked operations are executed first and acrid operations can be delayed until it's actually a bit more quiet in the system resources to execute the operation so what we can do is we can set the priority of an operation and we could say set it to very high because hey we have to use the triggered operation and I want to make sure that it's executed first so before we had the background operation being executed first and then used to target operation if I written it now again we can see that it used to get operation is executed first even though the background operation was edited at first this is a common way to do it however there's also another API which I wanted to show you which is the quality of service by default this is set to background if I'm right and for now we could say like hey this is used traded in other words user initiated so we can set it to that quality of service and that make sure that this operation is executed as soon as possible as you can see we first have to use the triggered operation and then the background upgrade this is great for doing like UI stuff where you wanna have a response as soon as possible and it's really easy to do helm of this queuing mechanism just by sending the quality of servers or by setting the priority I have like a certain sheet of feedback and I heard that the phone size could be a bit bigger so let's do that hopefully this makes it a bit easier for you to fill up so yeah let's say let's go to you an operation can be reused with the same instance of an operation can only be executed once and I can demonstrate that here we have to perform operation this is all working fine but say we use the same instance of the operation and we edit again we directly get a beautiful crash which is not telling us a lot but I'm pretty sure it's about adding the same instance again you can reuse the same type of operation but you have to create a new instance and then that works and then we come at the part of creating a custom operation and this is where operations really shine if you ask me I created an example of the air content input operation which we saw before in the slides it basically takes an item provider and we have to still write the logic for doing the actual importation I did the setup I set a completion block and I added through the queue if we run this now we will basically only get the input completed but let's do some implementation logic here for now this is this is only a synchronous operation so that's that's the default and to implement the logic we need to override the main method the main method is basically executed upon the start of the operation basically as soon as the queue triggers the operation and it's ready to be executed so what we can do here is Prince importing content of course this is not actually importing content but I don't want to spend time on that all right in that logic just imagine that this is the whole logic for inputting content and if we run this piece of code now we will see that we have the imported content and afterwards we have the importing completed this is the bare basic of creating a custom operation but yeah we will soon get into the more advanced versions but first I want to show you the different states of an operation because an operation could be an executing state as well as in a finished state or a canceled state and to show you that I've created the knife observer which basically observes every state change on an operation and prints that out to the to the console so I can bring this code and whenever you see a - that's basically a state change so we first have the executing which is set to true then we have the perform operation which comes from the main method then we have the operation completed which is coming from the completion block and after that the executing is set to false and finished set to true this is great so we now know how the operation is changing State but then it's interesting to see what happens happen if we cancel an operation before it's getting added to the queue so we under cancel and we ran the code again you can see that canceled stage is set to true and the operation is basically directly getting completed as soon as it's added to the queue this is great I mean the operation was canceled and due to multi trading or whatsoever it could be that it's still being added to the queue but we don't want it to actually execute and the operation class takes care of that makes that our main method is not getting caught however in multi-threaded environments it could also be that the operation is getting cancelled at the same time from a different threat in this case it's getting called directly after we added it and if we run it now [Music] we can see the canceled is set to true but after that still executing is set to true and the whole operation is performing and this is not what you want so we can prevent that by writing a little piece of code in our main method where we say like that we want to make sure that the operation is not canceled otherwise return immediately and don't before the operation so if we run this piece of code now again we can see that the perform operation is actually not triggered the rest of the states are still being managed but that's not really a big big of a problem for now this is perfect in our synchronous operation then I wanted to show you a bit of the dependencies so any dependencies between operations and in this example we have an import operation and the upload operation just like we had before in the slides and we set a completion block on each so we have an import operation completion where we say important completed and the same for upload completed we are we at operations and I did this on purpose where I'd set the upload operation before the input operation just to show you like the order of executing so we first have the uploading content started and then we have the importing content start however we wanna only upload once the input of the operation content is done so what we can do is we say template operation that at dependency and we say input operation and even though the upload operation is added at first in the array it will not execute earlier than that input operation fitness you can see it from the log-in protocol that started important is completed after that uploading content started and uploading completed this is great especially in a example where we have an upload operation that needs to be executed after importing this simply set a dependency and Europe basically all setup imagine you writing an app load content operation and it's a custom synchronous operation and you did what I just described you have the s cancels our property set however it doesn't make any sense to do the upload if the importing was canceled earlier before so we can make any operation that's dependent on another operation a bit more advanced by firstly checking whether the dependencies isn't any containing any operation that was cancelled before so we say dependencies contains where operation does is cancelled so what we basically say whenever the dependencies contain an operation that is cancelled we want to return so that's what we do with explanation mark here and this makes sure that our operation is never getting executed whenever it's dependencies were canceled before this is great once again this makes sure that we don't do any unnecessary work now we enter the fun part we're going to create an asynchronous operation and I'm going to do this in a manner of how you would probably do it yourself and wanna start with execute in this code to see what we have so we print out the state changes once again which you can see with the dash and we also print out the operation completed wherever the operation is done and we created a certain delay in our main method where we performed the operation a bit later and this is basically code to mimic sort of like a long-running task which could be like executing a certain end points for your API it's clear that we need an i synchronous operation here because once again if you look at this you will see that the perform operation will be printed out a bit later so okay you want to make this an asynchronous operation and you dive into the documentation where we can see and is a synchronous property it's straight right like let's overwrite that and we will have a sequence operation isn't it at least that's what I thought at the time so every turn through there we go and I execute it go nothing really changed and the reason for that is that we have to manage the states ourself and that kind of makes sense because we need to have a way to tell the cue like hey our asynchronous work is done so we will need a way to set like hey this operation is finished to do that we first need to take over the state management and to do that we need to override the start method and there we basically start by managing the same kind of state chases so we say is executing is true and then we get the following error because the es executing property is a gather only property there we go into the next step and we have to create our own override for that but because it's like a gun only property we can't simply override it and make it the set of all property as well so we need to create a private fire variable as well it's executing its defaults to false and we say it gets is returning is executing and the set is executing as new value this is enough to take away the warning which is great however there's a multi-threaded environment so you need to take care of synchronized access so we can't set this while it's also being read because that would be a data race and I'm not going to explain it in more detail there's another great Coco headstock which I did which you can watch online I'm pretty sure we can share the link afterwards for now let's create a a look you lookyou is dispatch cue label Coco adds dots I know I wonder whether this is the first effort look here with the coca and seeing it either way we can use this now and we can say think and we can do the same here that's sync this doesn't really change a lot but it only makes sure that there's only one thread accessing that it's executing property at a time and I just want to shortly note that this is not the most optimized way normally you would add an attribute concurrence which allows you to set a barrier flag and make read access a more performant however I want to keep it simple for this presentation and once again you can take a look at the data races talk at it before to have a bit more detail on that so let's execute the code again and see where we are this is pretty sad we don't get any any prints and that's because we need to call main ourselves now because we took hopefully start method and this would already improve the code because now we get the print statements of the perform operation however we still observe the state changes and we don't really see anything happening there and the reason for that is that we are handling with key vo a key value of persuasion and that's basically also how the cue works so at this point the operation cue is not getting any knowledge things that operation is either started or finished and that obviously breaks the whole operation cue so what we need to do is we'll change value for key where we say that is executing will be changed and I realized that this is the get normally would have had an audience to help me here but uh I'm all alone either way so far so good and now we can run it again and see what it does alright awesome so this is great because now we have the executed property which is set to true but we only need to create a finance method where we can say okay the perform operation has been done we're also done executing so we can say self let's finish and create a new method finish why we say it's executing is false and indeed it's finished oh I'm doing it one that is finished it's true and this requires us to create another property for its finished in this case which we can basically copy over this piece of code and call this it's finished copy that and paste it a few times here as well and here as well the it's famous property works exactly the same as is executing and we we need to handle this and this should be all to finish off our finish method so we can execute it once again this is great but we don't see the finished property still we can run it again because the fun fact is that it sometimes does print out and sometimes it doesn't either way one thing what you have to do because we're working with key feel we need to first let it know that it's set to fall so it's kind of like art but this is actually needed to make sure that this is a this line will actually do a key field change because if we run it now again we can see that it's doing exactly what we want its first changing finish to false then it's executing it does the perform operation then executing a set to false and the operation is completed and finished is true and it's good to realize that in the completion block it's not always true that the finished State is also set so if you do any comparison in the completion book to make sure that it's actually finished that wouldn't work but honestly oblation block is called when the operation is done so you don't really have to check that either way this is basically everything we need for a base class which which gives us an asynchronous operation and and the great thing is that you can now start using this for all kinds of tasks so let's go to the next page where we have an example of an asynchronous operation and and this is showing a bit more what it can be because honestly when you do this you commence procopio for the asynchronous operation i've written here you don't have to do that yourself the code you are actually going to write is the example code you see here where you create a new class which it's using a synchronous operation as its base class and in the main methods you're doing your asynchronous job which in this case is in the blood task as we have a file upload operation can handle the response and finally you've got Fitness to let them let them know that the operation is finished and something new which you didn't see before is that we override the cancel method here as well where we make sure to cancel your blood tasks because if your operation is cancelled you don't have to continue doing your blood this is great but we thought we can do better and reason is that we basically almost always work with results driven operations so we started creating an asynchronous result operation and this is where our generics will be introduced we first create a success generic and failure generic and then we make a new property which is privately settable only between a bull from the outside results it's an optional because it could be that in the beginning it's not yet set and then we get warning that failure needs to conform to this to the error type so we can do it but the where statement where we say well failure awesome alright so now we have a result but we want to make sure that the result is actually getting set and if we do just a bear fitness method we obviously wouldn't have a result so what we can do we can help our future self whenever we implement an operation so we can say fatal error this is a programming mistake you should use finish with to ensure a result of course we need to create a method so let's do that finish with results results success failure and then we can say sell that result is refilled and we call super got Finnish note that you have to go super because if we call self let finish it would still end up in the fatal error which wouldn't bring us a lot more this is great but we have another scenario which is cancellation so we need to do the same for cancel and override the cancel method let's say a fatal error you should cancel with to ensure every self and that we need to make that method as well cancel with and note that I'm only using error here because we think that we transfer that this is the case where like cancellation is kind of a failure setting of the operation in the end the operation isn't finished so it's kind of like you could spit as a fear that's at least how we handle it it does require you to create an error type with a cancelled case but it's at least or a lot nicer yeah I think it's it's better readable in that sense so what we can now do is set the result with that error and it all conforms to the same error type which is great and then once again we need to go super that cancel this is everything we need for an asynchronous result operation we can make it a bit more nicer as well where we create an over result callback which basically says that whenever I reserve the set you want to get a callback success and failure and the Twitter's fine and then we can say it says guard the result is result and then we say on result risotto this is great because now you can actually make use of the you can basically buy use this as your new completion block so whenever you have an asynchronous result operation you can set the own result property and print as yeah the result of the operation and I already created an example to show you exactly what what I mean with that and in this case we created an conferral URL operation which takes a short URL and returns the full URL so we created an unreserved callback as well where we print out the operation finished with and you could also already see it but let's just execute it once again and then you will see that it doesn't work maybe because the internet connection no I should have an internet connection because otherwise you can't hear me either way it's great that I had the previous print and printing out so yeah you could say that that it normally works but demo I'll have another example later on maybe that does the same but you get the idea this is basically outcome of the conferral operation I want to dive into an even more advanced implementation of operations because we realized that we transfer that we often have like dependency operations so as I showed before we have to come to the input operation and we have the content uploaded operation and they are basically always changed together so they also expect a certain input and given a certain output and that's why we created the change asynchronous result operation and it builds forward only a synchronous operation we had before so we can say input and failure type where failure that conforms to error and here we can say oh this should be output because it's the output of the asynchronous result operation of course it's to result and here we can say we want an input and output type and a failure tab this way we created an generic operation which takes a certain type as input gives the certain type of output and has a certain error type set and now we can create a private set up of our private set for input which is an optional because the thing is that the chain has to start somewhere and it could be there the first operation in the chain doesn't require any input so let's make an initializer for this dangerous input this allows us to image a large without an input as well we could say that it's default to mill and then solve the input this input and then all right this is great however we need to make sure that upon executing we actually have an input and as this is a change a synchronous result operation it could be that this is also the second operation in the chain and we want to have the input based on the output of the previous operation so to do that we can override the start method and we can say if input is still nil which means that we didn't initialize it with an input we could say so that's update input from the dependencies and afterwards we say superdad start to let it run just as normal we don't need software I always like to keep that clean and we can copy them in a method name to create a private thing they did put from dependencies so here we will run into a certain problem because we want to go over our dependencies cause them to an asynchronous result operation well basically I chained a sequence result operation and then we want to get the output and I can show you what I'm what I mean with that because if I do this and I say come back map to only return the operations that actually conform to it you say change asynchronous result operation this will not work because it requires you to give the the types as well so we can say change operation and then the first that's result gets as input and then self that input is yeah that's true because this is a try you know yes I try you know I started this is actually working it's kind of funny because I thought before that it wouldn't and that's why I also created this change operation out of profiling so maybe this presentation is in the ancestor of a rubber ducky operation presentation but either way I'll show you what I what I did before what I did before is I created an protocol within certain output of type any which is only got and then I had an extension for async result operation to conform to that up to profiling protocol say four outputs Eddie and return the try result that's guess and then what we could have done let's copy did this for the sake of the future and then we could say operation yes I'll put profiling that's first yeah of course output as input this was the way I did it before and then we don't have to try obviously because that's now replaced and moves into the output and this should be all to basically update the input from the dependencies and note that I said before that the first operation could have a new input and then this would still be executed but that's kind of fine because that first operation wouldn't have any dependencies so it would stay this the input would stay now this is great this is the only thing needed to create a change asynchronous result operation and this is also where when we can show the example and in this example I have the info URL change operation again which takes a short URL it's froze it which basically creates the long URL and then we have a fetch title change operation which fetches the title of the link and prints that out as well in the only self calling I'm pretty sure this will not work now as well maybe it does that's okay that's great the proof that my code is working actually either way let's let's go into the oil change operation first and as you can see we created the not change the synchronous result operation that takes us input the short URL which in this case is just the type alias of URL the output is set to a long URL which in this case is type Elias for URL as well and we have our error type [Music] in our main method we created basically the logic to infer the euro operation it's great for that where the code completion is not really helping us out here but you can see that we take the long URL from the response and whenever this short URL isn't returning a long URL then we finished nicely with a with a typed error and eventually we'll finish with the long URL there's also a cancellation which does the data tasks cancel and here you can see an example of the cancel method where we give the canceled case the Linotype and then we have to fetch style change operation and here we say that the input is a URL and the output is a string where this is basically a long URL but in theory you could also use a short URL so that's why we're going to type Elias and we have a string as an output which will be the title of the page I can go over this logic pretty sure we'll set the code online for you to to dive in it's kind of logic to simply get the title tag and get the value out of it and then once again you get this nice code where you have the unfair operation and the fetch title change operation which are dependent on each other through the dependency method and that's basically the implementation we have and we use heavily in the collective we transfer and I showed before the examples of imported content and uploading content and this is also an example where we have a short URL and a long hero and that is actually an example of a whole chain we have in collect where we first get a short URL of a transfer we convert it to a long URL we get the data and we finally import it it's really nice it's working out for us and hopefully this showed a bit to you as well what it can do and hopefully it's awesome the next cool thing I surely want to tie back to bring you back to the principles I said before because in our opinion the reason to go for operations it's allowing you to write code which is responsible for a single thing like importing content only or only upload in the content that allows you to write tests in a more easy manner you're really focused on a certain thing your test classes will probably be a bit simpler to maintain to do that as well last but not least this is all part of foundation you can use it directly support older iOS versions and it might also bring a shorter learning curve for your colleagues due to death a short shout-out to wait for good wait for good is a book which you can buy and all money will go to charity it's a great book with 20 different others from the community that all wrote their own chapter I did my chapter as well and not as a coincidence it's all about operations and I will explain there in a lot more detail how you can use operations and a bit more background story wells but not least I'm sharing every week new content on my personal blog swiftly I also got a newsletter with created contents which are send out every Tuesday check it out it's probably a really interesting for you to learn new things but with this nobody works great when I do talk and I have an audience you can pick your phone scan it and this will bring you to my Twitter if you want to follow me I have no idea whether this is long enough so I count to 5 for myself grab a bit of water and then I'm pretty sure you have had your chance and then that's it thank you very much I'm not hearing any applause I hope you're still with me it could be that I'm speaking to us and nobody for over 30 minutes now but um yeah I think it worked out hopefully all right I think we're going to have some questions now and I got some assistance with people picking up the questions for me so wait or input now I should probably check slick for that yeah there we go all right we got a big list all right cool okay so this is certainly a whole new thing to learn I need to read a question and come up with an answer Daniel Steinberg yeah all right so if I wouldn't have to support pre I with 13 would I instead go for combined or would I still prefer operations this is an interesting question because I think three years ago I did it told Anna it was a big supporter of functional reactive programming and as we transfer I kind of lost my belief and now combine is back it's an F of framework and that makes it kind of like easier to jump in that boat because it's no longer an external dependency so I mean that would would be a reason to not do it in that sense combined allows you to write a pretty nice code and the thing I dislike from combine at least right now it's bit harder to write your own custom publishers so say for example you have the content the import operation and you want to make that Kristin publisher that is at least for me right now not as easier to do you could obviously write an extension on publishers that could maybe then be the way way forward honestly right now today if I would support I was 13 enough I would still go for operations but it's also my personal preference because I'm really into operations right now and we kind of benefit from it every day that we transfer and it's a bit easier to understand for us and I think the code is a bit simpler as well in that sense and we don't have the learning core of functional reactive programming so I would say it depends on your situation and if it's a new project you start freshly and you don't know but you don't know much about the operation yet as well then you have a learning curve for both and then it could be or I'm just as good a choice to go for combined I think I hope this this answers your your questions in general and otherwise feel free to ask for more details later on next question I have quite a lot of questions I'm pretty sure I can't go over all of them so let's let's pick a few yeah so Lambert asked me why do you think operations never got very popular and people prefer to use things like Eric Swift yeah that's a good question I think our expressed is in general just really a cool kind of framework is driven by open source community so maybe it got got a bit more shoutouts it's also true that it's available in all different languages so R X Y alpha and those kind of frameworks which helps in the build as well and in terms of operations I mean it's not developed by the source community so there's not a lot of shout out around it as well but still yeah I mean I hope this presentation helps to make the the the group behind operation is a bit bigger but it's really hard for me to say like why white never got really popular yeah curious about your opinion on that as well yeah so there's a few questions about will the project be sure I don't get up how I make sure to do that hopefully I can do it tomorrow and then Bruno asked me what is the most non-obvious part if we transfer they use operations for so let me give me a cheat where I can go back to the slide with all the braces on it so there's there's a few here and let me see I mean they all make kind of sense to me at least because I know them yeah I don't know I think all the operations are built with a certain ID behind it right so well yeah it's it's actually doing a certain problem it's doing syncing to the backend and file operations importing operations like video assets and yeah I don't know yeah for for me they're all really obvious but if I come up to mind with a different operation I'll let you know yes temple code again yeah the same question Israel oh yeah a lot of the same questions kind of asking like whether combined will replace operations yeah lumber tasks an interesting question is there a convenient way to deal with retries of network errors my answer to that would be to solve this in your networking framework and not per se in your operations and in your networking framework you could basically catch response before it's going back to your implementation level and wait with returning the result before you retry it at least one time war if you want to see an example of that we're using a llama fire for that a llama fire has to read retire which works really nice for that and it allows you to easily retry a few times before returning the response I know that frameworks like combine are a lot easier with this you simply have an operator for that however yeah I mean it's at least the answer in terms of operations in this case so Axl comes with a interesting question I have not dived into combine too much but is it possible to create a task slash operation and distribute hundreds of them along multiple processors so what you will run into is the maximum concurrent operation count shortly showed that in in the first page of the playground because the system has a certain resources available for your operations to execute and by default it basically takes as much as it can based on the current available system resources but it could be for example if your phone is on low on battery it will only allow your app to actually get to at the same time so even if you distribute hundreds of them yeah there will be maxed out pretty sure it's the completion always code is what Marius asks also when an operation is cancelled as far as I know it is because an operation is still completing when it's cancelled it's just not not succeeded but the operation API itself doesn't know where it's succeeded or not it knows that it's canceled or or not so yeah the completion Kovac is always always called yeah then question for a from Remy can they coexist when nobody CD asynchronous calls if you mean that you can use G CD inside operations then yes that that's possible if you wanna like depends GCD dispatch block on an operation I think that's that's been harder but yeah I don't forget that operation queue is basically a higher level implementation based on top of GCD so yeah I'm not sure whether this is actually a scenario you you need to need the support but either way yeah I think that they should work together if you use them inside an operation yeah machito also asked whether the playground will be available I'll share that out on my Twitter as well as in my newsletter out upcoming Tuesday so if you don't want to miss it you can subscribe there and I don't get any any questions so this is it yeah with 90 people watched it so that's that's good to know I wasn't alone all the time it did feel a bit by that I mean I didn't get any response but yeah I think thanks a lot everyone if you have any questions and you really want to have an answer feel free to reach reach out to me on Twitter or in the cocoa heads like I'm available there as well I'm happy to chat with you and see if I can answer any of your questions you
Info
Channel: CocoaHeadsNL
Views: 1,936
Rating: undefined out of 5
Keywords: CocoaHeadsNL, CocoaHeads, iOS
Id: T0wMEVBIZMg
Channel Id: undefined
Length: 58min 39sec (3519 seconds)
Published: Sun Mar 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.