ios - How to auto dispatch_group_leave -


i'am using dispatch_group manage multi-threads in project. this:

- (void)functiona{     self.taskgroup = dispatch_group_create();      // call functionb more 1 time     [self functionb];     ...     [self functionb];      dispatch_group_notify(..., ^{         // if [self functionb] complete     });  - (void)functionb{     dispatch_group_enter(self.taskgroup);      if (condition) {         dispatch_group_leave(self.taskgroup);         return;     }      [self dosomethinginbackground:^{         nslog(@"completed!");         dispatch_group_leave(self.taskgroup);     }]; } 

my question how automatically call dispatch_group_leave when functionb complete, don't need call before every return statement in functionb or background task called functionb.

as @sk0prion mentioned in comments, can involve macro here.

#define m_return dispatch_group_leave(self.taskgroup);return 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -