I'm scheduling stream objects on run loops, and the server retrieves the correct information etc, however after dispatching requests to write to the NSOutputStream I am receiving events a lot later than expected, screwing up control flow. I handle events using the following method from the NSStreamDelegate protocol :
- (void)stream:(NSStream*)theStream handleEvent:(NSStreamEvent)streamEvent
I am calling the query as follows, and the events aren't received until the loops have been exit :
for (NSMutableArray* objs in allObjs) {
for (Obj* o in objs) {
[self searchQuery:[NSString stringWithFormat:@"%@ foo", o.bar]];
}
}
I tried creating a global variable that flags whether the most recent dispatched event has been processed, this is looped over before iterating again in the inner for loop, but runs indefinitely.
How should I correctly wait for each result from the queries before iterating again in the inner for loop?
Thanks in advance! :)
Side note : My iOS app is using TCP sockets to communicate with a server I have written in Python, following this tutorial by Cesare Rocchi.