• 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: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?


  • Subject: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • From: Jean Suisse <email@hidden>
  • Date: Wed, 08 May 2013 01:06:22 +0200

Thanks for this suggestion. Actually, once identified, I fixed the bug fairly quickly by postponing the task (dispatched a block on the main thread for that).
The bug was caused by two successive events arriving in a short timeframe so that the stack looked like that:

0 my callback
1 __CFSocketPerformV0
------------------------------------
9 initWithHTML:dataUsingEncoding:documentAttributes:
10 my function 1
11 my function 2
12 my callback
13 __CFSocketPerformV0
-----------------------------------
23 NSApplicationMain
24 main
25 Start

and my callback never was designed to be called a second time before the first call was finished. Dispatching a block to handle my function 1 fixed the issue.
However, information about initWithHTML:dataUsingEncoding:documentAttributes: running an event loop could be worth mentioning in the docs…

Jean


On 8 mai 2013, at 00:52, Ken Thomases wrote:

> On May 7, 2013, at 5:37 PM, Jean Suisse wrote:
>
>> By any chance, could a call to [[NSAttributedString alloc] initWithHTML:dataUsingEncoding:documentAttributes:] lead to the event loop being run before the call returns?
>
> Yes, it can.  Under the hood, NSAttributedString is using WebKit for HTML rendering.  In part that means that, when invoked from a background thread, it has to shunt the work to the main thread.  But it also means the main thread may have to run the run loop during the call.  It's a nuisance, but it's necessary since HTML can have references to external resources that need to be loaded.
>
> Consider the other method, -[NSAttributedString initWithHTML:options:documentAttributes:] and its options dictionary, which can have keys like NSTimeoutDocumentOption and NSWebResourceLoadDelegateDocumentOption.  Those imply a pretty involved process under the hood.  I'm fairly certain that this method is used for the implementation of the method you're using.
>
> You may be able to use those options to minimize the use of the run loop, but probably not eliminate it.
>
> Regards,
> Ken
>

-----------
Jean Suisse
Institut de Chimie Moléculaire de l’Université de Bourgogne
(ICMUB) — UMR 6302
_______________________________________________

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: 
 >Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop? (From: Jean Suisse <email@hidden>)
 >Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • Next by Date: Re: Showing numpad key equivs in menu items
  • Previous by thread: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • Next by thread: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
  • Index(es):
    • Date
    • Thread