• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get the dispatch queue for the current thread's runloop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get the dispatch queue for the current thread's runloop?


  • Subject: Re: How to get the dispatch queue for the current thread's runloop?
  • From: Conrad Shultz <email@hidden>
  • Date: Fri, 27 Jan 2012 14:27:56 -0800

On 1/27/12 12:14 PM, Jens Alfke wrote:
> I'm really used to using -performSelector:withObject:afterDelay: to
> make something happen later. But I'd much rather use a block than a
> target/action. I can't find any API for this, however. Am I missing
> something? What I want is basically like PerformBlockAfterDelay(^{
> …code here…}, 5.0);

Take a look dispatch_after().

The main downside I have found to using this is that there is no
(direct) analog to cancelPerformSelector.  Most the idioms I have seen
involve having the block check a variable (i.e. "BOOL stop") to
determine whether they should continue executing.

An alternative technique is a category on NSObject that has
perform:/cancelPerform: methods accepting block arguments but using
performSelector: internally to fire the block (or cancel firing).  Mike
Ash has a blog post that touches on this approach
(http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html).

--
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >How to get the dispatch queue for the current thread's runloop? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: How to get the dispatch queue for the current thread's runloop?
  • Next by Date: Re: Full-Height Toolbar Item
  • Previous by thread: Re: How to get the dispatch queue for the current thread's runloop?
  • Next by thread: Re: How to get the dispatch queue for the current thread's runloop?
  • Index(es):
    • Date
    • Thread