Re: Best pattern to follow for scheduling an event
Re: Best pattern to follow for scheduling an event
- Subject: Re: Best pattern to follow for scheduling an event
- From: John Stiles <email@hidden>
- Date: Thu, 8 Nov 2007 11:03:49 -0800
On Nov 8, 2007, at 10:57 AM, glenn andreas wrote:
On Nov 8, 2007, at 12:43 PM, John Stiles wrote:
I think I'm not explaining myself well enough.
The typical pattern is that my method will get spammed a hundred
times in quick succession. After the burst of calls has completed,
I want to do fix-up. Technically, I could do my fix-ups after
every single call, but that would probably be slow so I want to
avoid it. This doesn't mean that the method will never get called
again—much later on in app execution, it's quite possible that my
method will suddenly get spammed again with hundreds of calls, and
then I will want to do fix-ups again.
Then have you doFixUp: routine reallocate the m_deferredFixupTimer,
so the next time that the "do something" trigger is hit, it can be
scheduled again.
There is an inferred state that if m_deferredFixupTimer were nil,
there is a pending cleanup, otherwise it means that the thing is
currently clean (and the next time it made dirty, it will schedule
a cleanup)
You could even tweak the date value to guarantee that, for example,
the cleanup only happens once every 5 seconds... (if, for example,
part of the cleanup is to tell the user something has been updated)
I guess I am struggling to see the advantage of doing things that way
because it's more lines of code and more real work. (Extra if
statements involved, you have to allocate and dispose the timer
repeatedly, etc.)
I think Joar's suggestion of a notification queue is probably the
best approach, but it's a little more heavyweight than a timer. I
might go that route if I find that I need more flexibility.
_______________________________________________
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