在Swift中C#async await
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在Swift中C#async await,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1419字,纯文字阅读大概需要3分钟。
内容图文
![在Swift中C#async await](/upload/InfoBanner/zyjiaocheng/789/6744229e6ae24c21b156d078845382a0.jpg)
我正在玩Swift中的闭包和链接完成.我非常熟悉异步的C#样式并等待,所以我想知道如何将以下代码片段从C#“转换”为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);
}
}
Swift是否有类似await的类似构造,等待函数完成,而不必嵌套多个完成块?
谢谢
解决方法:
如果我没有误会,你在寻找的是:
串行调度队列:
Serial queues (also known as private dispatch queues) execute one task
at a time in the order in which they are added to the queue. The
currently executing task runs on a distinct thread (which can vary
from task to task) that is managed by the dispatch queue. Serial
queues are often used to synchronize access to a specific resource.
You can create as many serial queues as you need, and each queue
operates concurrently with respect to all other queues. In other
words, if you create four serial queues, each queue executes only one
task at a time but up to four tasks could still execute concurrently,
one from each queue. For information on how to create serial queues,
see Creating Serial Dispatch Queues.
斯威夫特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")
}
内容总结
以上是互联网集市为您收集整理的在Swift中C#async await全部内容,希望文章能够帮你解决在Swift中C#async await所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。