ios - does calling cancelPreviousPerformRequestsWithTarget: on a selector cancel internal method calls as well? -


i have selector method performs search particular text in 2 different libraries in 2 different threads called using dispatch_async.

now selector bound textfield , characters change can query libraries text.

now search takes time 0.3 - 0.4 second , if first search not complete before character entered woould cancel search , re-start new characters in text field.

so calling cancelpreviousperformrequestswithtarget on selector cancel internal threads , libraries call...?

no. cancelpreviousperformrequestswithtarget has nothing blocks dispatched via gcd (i.e. dispatch_async). cancels previous invocations of selectors scheduled later time on specific nsrunloop using -performselector:withobject:afterdelay:. furthermore, can't cancel invocations if they're in progress, can prevent them starting, if they're still waiting begin.

there no means (safely) forcibly cancel in flight operations, regardless of method used dispatch them. operation has to, itself, support cancel-ability, checking flag periodically during work, , returning if flag says operation should cancel.

because inevitably come along , nsoperation supports cancelation, might out of way now, pointing out nsoperation's cancelation support still requires operation being canceled periodically check flag , intentionally return early, it's nsoperation has cancelled property provides flag you. useful you, code has know it's executing part of nsoperation, , has have pointer specific nsoperation it's executing part of, , still has periodically check cancelled property of nsoperation , return in order "support cancellation."

there no free lunch cancellation on non-garbage-collected runtimes.


Comments

Popular posts from this blog

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