Your question is really abstract 1. Receiving or sending data is an independent function, assuming it is sendRead, separate it from the business. In this way, when receiving data, just receive the data. When the data reaches the standard you want, call back from the sendRead module. readFromSocket(buffer) This method can be transformed into a style with a closure (block) callback:
When your business execution reaches a certain stage and you need certain data, call this and then process it in the callback. At this time, the callback only needs to handle the logic of this stage. Although this still cannot make sequential calls, because receiving data cannot be completed at once, and it must wait for the data recipient to proactively notify. 2. I see that you have to make multiple status judgments in handleData. Is this business running with multiple threads at the same time? If not, it would be simpler, because the APP is currently in one state, and you only need to collect the data of a single state first and then throw it to the business code for processing. Otherwise, the business logic must be separated, and the read operations must also be separated.
Your question is really abstract
1. Receiving or sending data is an independent function, assuming it is sendRead, separate it from the business. In this way, when receiving data, just receive the data. When the data reaches the standard you want, call back from the sendRead module.
readFromSocket(buffer)
This method can be transformed into a style with a closure (block) callback:
When your business execution reaches a certain stage and you need certain data, call this and then process it in the callback. At this time, the callback only needs to handle the logic of this stage. Although this still cannot make sequential calls, because receiving data cannot be completed at once, and it must wait for the data recipient to proactively notify. 2. I see that you have to make multiple status judgments in handleData. Is this business running with multiple threads at the same time? If not, it would be simpler, because the APP is currently in one state, and you only need to collect the data of a single state first and then throw it to the business code for processing. Otherwise, the business logic must be separated, and the read operations must also be separated.
Why so many spelling mistakes?
ReactiveCocoas or RxSwift