<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          KillerRabbitTHGDispatch 模塊

          聯(lián)合創(chuàng)作 · 2023-09-28 16:17

          KillerRabbit 是 THGDispatch 模塊,包括 GCD bits:Queues, Groups, Timer, Semaphore 等等。

          使用:

          執(zhí)行異步閉包:

          Dispatch().async(.Background) {
              doSomething()
          }

          在后臺(tái)隊(duì)列執(zhí)行異步閉包:

          Dispatch().async(.Background) {
              doSomething()
          }.notify(.Main) {
              dearMainThreadImDone()
          }

          執(zhí)行一個(gè)異步閉包并等候 3 秒:

          Dispatch().async(.Background) {
              doSomething()
          }.wait(3) == false {
              itTimedOutImSad()
          } else {
              itWasSuccessfulAndMyLifeHasMeaning()
          }

          執(zhí)行一些異步任務(wù):

          DispatchGroup().async(.Background) {
              doSomething(1)
          }.async(.Utility) {
              doSomething(2)
          }.async(.High) {
              doSomethingUrgently(3)
          }.wait()

          或者:

          let group = DispatchGroup()
          
          group.async(.Background) {
              doSomething(1)
          }.async(.Utility) {
              doSomething(2)
          }.async(.High) {
              doSomethingUrgently(3)
          }if group.wait(10) == true {
              handstandAndCartwheel()
          }

          執(zhí)行一個(gè)異步任務(wù),同步一個(gè) Semaphore:

          let semaphore = DispatchSemaphore(initialValue: 0)// start a NSURLSession to get some data from our imaginary command line tool.let task = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
              if data != nil {        let dataString: String = NSString(data: data, encoding: NSUTF8StringEncoding)! as String
                  json = JSON(string: dataString)
              }
          
              semaphore.signal()
          }
          
          task.resume()
          
          semaphore.wait()


          瀏覽 18
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  人人射人人草 | 爱弓凉免费无码一区二区 | 在哪能看爱爱网站 | 最新的成人豆花AV | 青娱乐精品 |