First I create a serial queue like this
static dispatch_queue_t queue = dispatch_queue_create(\"myQueue\", DISPATCH_QUEUE_SERIAL);
then, at som
With Davids answer getting me on track I succeeded in doing this like so
taskCounter++;
dispatch_async(queue, ^{
if (taskCounter > 1) {
taskCounter--;
NSLog(@"%@", @"skip");
return;
}
NSLog(@"%@", @"start");
// do stuff
sleep(3);
taskCounter--;
NSLog(@"%@", @"done");
});
taskCounter
has to be either an ivar or a property (initialize it with 0
). In that case it doesn't even need the __block
attribute.