Swift
                
              Swift: async let 수행 순서
                songmoro
                 2025. 3. 30. 18:04
              
              
                    
        728x90
    
    
  async let의 수행 순서는 await 순서에 따름
func function(_ name: String, _ i: Int) async -> Int {
    print("sleep: ", name, i)
    sleep(UInt32(i))
    print("wake up: ", name, i)
    return i
}
async let a = function("a", 10)
async let b = function("b", 3)
async let c = function("c", 2)
async let d = function("d", 5)
async let e = function("e", 3)
async let f = function("f", 5)
async let g = function("g", 3)
async let h = function("h", 4)
async let i = function("i", 1)
async let j = function("j", 5)
print(await a, await b, await c, await d, await e, await f, await g, await h, await i, await j)sleep:  a 10
sleep:  b 3
sleep:  c 2
sleep:  d 5
sleep:  e 3
sleep:  f 5
sleep:  g 3
sleep:  h 4
wake up:  c 2
sleep:  i 1
wake up:  g 3
wake up:  b 3
sleep:  j 5
wake up:  e 3
wake up:  i 1
wake up:  h 4
wake up:  d 5
wake up:  f 5
wake up:  j 5
wake up:  a 10
10 3 2 5 3 5 3 4 1 5728x90
    
    
  