What are benefits of NSRunLoop vs dispatch_source_t timer vs ReactiveCocoa bindings

138 views Asked by At

For learning purpose I'm building a visual programming application on OSX. Basically it is made of one function nodes connected through output -> inputs and forming a graph.

I'm building the connected graph (with CoreData) by using depth-first search, then each node is executed in the graph queue with :

NSTimeInterval secondsToFire = 1./250.;

NSString *dispatchName = [NSString stringWithFormat:@"info.oz432.timer.queue.%p", self];
dispatch_queue_t queue = dispatch_queue_create([dispatchName UTF8String], 0);

_timer = [self createWithInterval:secondsToFire inQueue:queue usingBlock:^{
    for (NSManagedObject *node in pipeline) {
        [self executeNode:[node objectID] inQueue:queue];
    }
}];

With -createWithInterval:inQueue:usingBlock:

dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);

if (timer) {

    dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), interval * NSEC_PER_SEC, interval * NSEC_PER_SEC);
    dispatch_source_set_event_handler(timer, block);
    dispatch_resume(timer);

}

return timer;

It's working quite well for now, but I'm wondering:

  • if using ReactiveCocoa to connect signals from outputs to inputs would be a simplest/more readable/more performant solution;
  • otherwise, why should I choose to run a NSRunLoop for each of my 'pipelines'.

I've read a lot about NSRunLoop, I can see that people involved in ie. GStreamer in Cocoa are managing with NSRunLoop, and that Vuo is using it. I guess I understand the basics of it. But I don't understand, and this is my question: what are the benefits of it ?

0

There are 0 answers