Home > Mobile >  Asynchronously send data how to implement wait for, that is, asynchronous synchronous
Asynchronously send data how to implement wait for, that is, asynchronous synchronous

Time:09-24

Everybody is good, I wrote a socket chat demo, data sending is asynchronous, but I need to wait for sending as a result, how to realize the wait? I don't want to use an asynchronous callback, a lot of trouble,

CodePudding user response:

The GCD know

CodePudding user response:

Can you give an example

CodePudding user response:

Can use the GCD semaphore dispatch_semaphore_t to implement, but feel so there will be a question, cause caton application

CodePudding user response:

https://www.jianshu.com/p/2d57c72016c6
This article has a detailed introduction to the use of a semaphore

CodePudding user response:

The semaphore

CodePudding user response:

Use java8 CompletableFuture or CountDownLatch or awit () to implement wait for


Dubbo use CompletableFuture
Canal, and some open source framework using CountDownLatch
I hope it can help you

CodePudding user response:

Then write logic ~ in the callback
  •  Tags:  
  • iOS
  • Related