I use tcp socket to receieve the data from server(about 100 times in one second) , When I receieve the data ,I want to push it into an array by delay 200ms, How to do?
Asked
Active
Viewed 143 times
1 Answers
0
You can use dispatch_after to run a closure after a specified amount of time. You just need to determine which of the queues your closure should run on, documentation on the queues and their purpose here:
For this example I'll use QOS_CLASS_UTILITY which is intended for long running background tasks.
let qos = Int(QOS_CLASS_UTILITY.value)
let delayInMilliseconds = 200
let delay = Int64(delayInMilliseconds * Double(NSEC_PER_MSEC))
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, delay)
dispatch_after(dispatchTime, dispatch_get_global_queue(qos,0)) {
//code to push data into array
}

Jackalope
- 116
- 1
- 5