C # async waiting in Swift

Currently, I'm playing with the closure and strings Swift. I am very familiar with the style C# asyncand await, therefore, I was wondering how to "translate" the next fragment from C#to Swift.

public async Task SomeFunction(string inputString)
{
    var first = await GetFirstVariableAsync(inputString);
    var second = await GetSecondVariableAsync(first);

    if (second == "some condition")
    {
        first = await GetFirstVariableAsync(inputString);
        var second = await GetSecondVariableAsync(first);
    }
}

Does it have a Swiftsimilar construction, such as awaitto wait for a function to complete without having to embed multiple completion blocks?

thank

+4
source share
2 answers

If I'm not mistaken, then what are you looking for:

Serial dispatch queues:

( ) , . ( ), . . , , . , , , , . , , . .

Swift 3:

let serialQueue = DispatchQueue(label: "serialQueue")

serialQueue.sync {
    print("running first task")
}

serialQueue.sync {
    print("I will wait the first task and then I'll do my own task")
}
+1

concurrency in Swift language . Swift 5 Swift evolution, : concurrency. Cocoa/Cocoa touch, Dispatch, , . concurrency Swift

+1

Source: https://habr.com/ru/post/1662525/


All Articles