0

概述

  • 我有一个f1非异步函数。
  • f1被多次调用,我无法控制调用f1
  • 当 f1 被调用时,我想调用一个异步函数f2

目标:

  • 我想f2在下一次f2执行之前完成

问题:

  • 如何确保f2按顺序执行?(下面的示例代码)
//I have no control over f1
//f1 can get called multiple times in quick succession.
func f1() {
    Task {
        try await f2() // Next time f1 gets called it should wait for the previous f2 to complete then should execute f2
    }
}

func f2() async throws {}
4

0 回答 0