Re: BIG Thread problem (theorical).. need some advice.
Re: BIG Thread problem (theorical).. need some advice.
- Subject: Re: BIG Thread problem (theorical).. need some advice.
- From: Gustavo Pizano <email@hidden>
- Date: Tue, 26 Jan 2010 14:30:17 +0100
Aha, so if I understood good, you use Notifications instead, so when the LoadDelegate finish it post the notifications, and then my controller which I should have added to listen to a given notification and perform the given selector, can get the dictionary having for sure it has some data which was instantiated in the loadFrame delegate method of webView.. am I right?
Gustavo?
On Jan 26, 2010, at 2:13 PM, Louis Gerbarg wrote:
> On Tue, Jan 26, 2010 at 7:52 AM, Gustavo Pizano <email@hidden> wrote:
>
> I duno if its the best solution but it works.. Im open to hear other approaches...
>
>
> This isn't a threading issue, everything is happening on a single thread. The issue is that you have a synchronous API that depends on an asynchronous API underneath. You have correctly deduced that one way to handle this is to spin in a loop (in this case an event loop) waiting for the asynchronous API to complete so you can return the data. In many cases that is a reasonable solution, though if you get several of these things nested together or are using weird runloop modes you can start to have some very complex behaviors. You also potentially need to make sure any code in the call stack leading up to that runloop reentrant, depending on exactly what you are doing.
>
> Personally, I prefer to make my design asynchronous all the way up and down the stack. So instead of implementing something like:
>
> -(NSDictionary *)pListWithWebElements;
>
> I might do:
>
> - (void) updatePListWebElements; //Exact same IMP except it doesn't return anything
>
> and then in the load delegate:
>
> #pragma mark LoadFrameDelegate.
> -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame{
> //Your original code
> ....
>
> [[NSNotificationCenter defaultCenter] postNotificationName:@"PListWithWebElementsLoaded" object:self];
> }
>
> which would then fire an NSNotification at the time it was updated, and I would just register a notification handler to deal with it. Depending on the exact nature and complexity of what is going on it may also be apropriate to implement your own delegate protocol and make calls into the delegate just like the system does with your delegates.
>
> Louis
>
_______________________________________________
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