Re: wait for the event?
Re: wait for the event?
- Subject: Re: wait for the event?
- From: Matthew Mashyna <email@hidden>
- Date: Tue, 6 Oct 2009 00:00:38 -0400
Well, I'm an old fart too so I'll try to make one more point and maybe
that will help. Once the bulb goes on over your head you'll love the
asynchronous nature of Cocoa. Let asynchronicity work for you. Put
things in motion and let them tell you when they are done instead of
watching them.
If you bake brownies you can sit in front of the oven and watch the
timer or you can do something else until the timer beeps to tell you
they're ready. That's what the notification center is all about.
WebViewProgressFinishedNotification will tell you when it's time to
open the oven.
You're baking your brownies in one set of steps. I want you to have
two sets of steps: before you start the timer steps and after the
timer beeps steps. Between these sets of steps you can do whatever you
want or do nothing or do what the Mrs tells you to do (or since we're
old we might nap). When the timer beeps you finish the job.
I THINK what you are doing, more or less is something like this:
-(void) awakeFromNib
{
createMyWebView;
startMyWebviewLoading;
while(mywebview != loaded) // the phone is ringing but you can't
answer because you have
wait; // to keep an eye the brownies. You're the jackpot winner
if only you could answer.
processTheDOMstuffFromMyWebView;
}
When what I would do would be a two step approach -- without needing
locks by the way
-(void) awakeFromNib
{
createMyWebView;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(webViewProgressFinished:)
name:WebViewProgressFinishedNotification object:myWebView];
startMyWebviewLoading;
// they're in the oven, timer's on!
// nap, read letters to the editor from people who write
incoherently, watch kitties on YouTube
}
- (void)webViewProgressFinished:(NSNotification*)notification
{
// Bing! They're done, wake up and get back to work
processTheDOMstuffFromMyWebView;
}
If you have a bunch of webviews you could find a scheme to wait until
they have all finished before final processing. Make a queue of them
maybe but for this you want to look into using the @synchronized
directive in webViewProgressFinished when you move things in and out
of the array.
Look here for more about synchronization. http://developer.apple.com/iPhone/library/documentation/Cocoa/Conceptual/Multithreading/ThreadSafety/ThreadSafety.html
On Oct 5, 2009, at 9:58 PM, jon wrote:
oh you've got that right, I unfortunately have it ingrained for 25
years of straight pascal in MacOS... i could destroy a runloop with
the best of them...
I wish i started cocoa 7 years ago, but it was not to be..... My
brain is trying to refactor, and it is fighting mightily... trying
to keep up with the young-uns who have no such baggage...
I'll look into NSLock thanks,
Jon.
On Oct 5, 2009, at 7:45 PM, Matthew Mashyna wrote:
you need some time to come around to a different way of thinking.
You are thinking too linearly.
_______________________________________________
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