• 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: Best pattern to follow for scheduling an event
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best pattern to follow for scheduling an event


  • Subject: Re: Best pattern to follow for scheduling an event
  • From: glenn andreas <email@hidden>
  • Date: Thu, 8 Nov 2007 12:25:04 -0600


On Nov 8, 2007, at 12:05 PM, John Stiles wrote:

I have a method that needs to schedule a "cleanup pass" to occur in the near future. The method might be called once, ten times, or a hundred times in a row, but I only need to clean up one time. To implement this, I used the following pattern, and I'm wondering if it was the best way to go.

First, when the object is first created, I create a timer. I scheduled its fire date to be in the distant, distant future:

   m_deferredFixupTimer = [[NSTimer
       scheduledTimerWithTimeInterval:DBL_MAX
                               target:myObject
                             selector:@selector(doFixUp:)
                             userInfo:NULL
                              repeats:YES] retain];

Then, when my method is called, I schedule the timer to fire immediately:

[m_deferredFixupTimer setFireDate:[NSDate date]];

What about:
m_deferredFixupTimer = [[NSTimer alloc] initWithFireDate: [NSDate distantFuture] interval: 0 target: myObject selector: @selector(doFixUp:) userInfo: NULL repeats: NO];



and then to get it to fire immediately

	[m_deferredFixupTimer fire];


This defers the fire to the next run-through of the event loop, which for my purposes is sufficient. It only fires one time.


Or if you want it to be the next event loop

[[NSRunLoop currentRunLoop] addTimer: m_deferredFixupTimer forMode: NSDefaultRunLoopMode];
[m_deferredFixupTimer setFireDate: [NSDate date]];



Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next generation of fractal art




_______________________________________________

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


  • Follow-Ups:
    • Re: Best pattern to follow for scheduling an event
      • From: John Stiles <email@hidden>
References: 
 >Best pattern to follow for scheduling an event (From: John Stiles <email@hidden>)

  • Prev by Date: Re: Best pattern to follow for scheduling an event
  • Next by Date: Interface Builder "layout" versus "frame"
  • Previous by thread: Re: Best pattern to follow for scheduling an event
  • Next by thread: Re: Best pattern to follow for scheduling an event
  • Index(es):
    • Date
    • Thread