Vote count:
0
I have an application which on user logout would suspend all threads. If the user relogin's we need to restart this queue.
I have added all the dispatch_queue_t object to an array. When the user logouts, I iterate through this array and suspend them as below:
- (void)suspendAllQueues{
for (dispatch_queue_t queue in self.dispatchQueueArray) {
NSLog(@"queue: %@",queue);
dispatch_suspend(queue);
}
}
The queues are defined inside the singleton (init) method
+ (APIManager *)sharedInstance
{
static APIManager *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
allowInstantiation = YES;
sharedInstance = [[APIManager alloc] init];
allowInstantiation = NO;
});
return sharedInstance;
}
- (id)init
{
if (!allowInstantiation) NSLog(@"Instantiation of singleton not allowed.");
if (!(self = [super init])) return nil;
// Async queue for updating user information
updateUserInfoQueue = dispatch_queue_create("com.test.updateuserinfoqueue", DISPATCH_QUEUE_SERIAL);
// Async queue for logging in , facebook login and registration login
loginoutQueue = dispatch_queue_create("com.test.loginoutqueue", DISPATCH_QUEUE_SERIAL);
//Async queue for general tasks (password reset, email verification and social sharing)
generalAsyncQueue = dispatch_queue_create("com.test.generalasyncqueue", DISPATCH_QUEUE_SERIAL);
self.dispatchQueueArray= [NSMutableArray new];
return self;
}
When I tried to load a method using the generalAsyncQueue it doesn't start. I suspended the queue on logout. What would be a better method to stop the method called by generalAsyncQueue?
asked 59 secs ago
Reusing suspended dispatch_queue_t - iOS
Aucun commentaire:
Enregistrer un commentaire