In the next step I need to vend a promise that I will resolve later--possibly never.
I think I need a cycles-defeating promise, something like a ScriptPromise with a weak handle and an hidden property from wrapper to promise. Can you give me some implementation pointers?
Here's my situation:I have an object, navigator.serviceWorker, that vends promises through a "ready" property.The implementation today is very simple, because it either returns a resolved promise, or never resolves the promise. In both cases it creates a promise and hands it back to the user.In the next step I need to vend a promise that I will resolve later--possibly never.
On Jun 9, 2014 11:09 PM, "Yutaka Hirano" <yhi...@chromium.org> wrote:
>>
>> In the next step I need to vend a promise that I will resolve later--possibly never.
>
> Sorry I 'm not sure what you meant, so let me confirm.
> Do you want to return the same promise over multiple calls for "ready"?
I don't think the spec requires that, and I was planning on returning multiple different ones. How is the multiplicity important?
On Jun 10, 2014 8:09 AM, "Adam Barth" <aba...@google.com> wrote:
>
> On Mon Jun 09 2014 at 10:52:53 PM, 'Dominic Cooney' via blink-dev <blin...@chromium.org> wrote:
>>
>> I think I need a cycles-defeating promise, something like a ScriptPromise with a weak handle and an hidden property from wrapper to promise. Can you give me some implementation pointers?
>>
>> Here's my situation:
>>
>> I have an object, navigator.serviceWorker, that vends promises through a "ready" property.
>>
>> The implementation today is very simple, because it either returns a resolved promise, or never resolves the promise. In both cases it creates a promise and hands it back to the user.
>>
>> In the next step I need to vend a promise that I will resolve later--possibly never.
>
>
> Is there some point at which you know that you'll never resolve the promise? That's the point at which to break the cycle. For example, we typically break these cycles when the ActiveDOMObject::stop notification is called.
I think it is the frame navigating. So navigator.serviceWorker, which is already a ContextLifecycleObserver, should simply use that as a signal to relinquish the Promise handles?
> One difficulty with using weak processing to define the point at which the promise will never resolve is that we'll leak some implementation details about when we trigger garbage collection.
Leak implementation details to whom?
On Jun 10, 2014 8:09 AM, "Adam Barth" <aba...@google.com> wrote:
> On Mon Jun 09 2014 at 10:52:53 PM, 'Dominic Cooney' via blink-dev <blin...@chromium.org> wrote:
>>
>> I think I need a cycles-defeating promise, something like a ScriptPromise with a weak handle and an hidden property from wrapper to promise. Can you give me some implementation pointers?
>>
>> Here's my situation:
>>
>> I have an object, navigator.serviceWorker, that vends promises through a "ready" property.
>>
>> The implementation today is very simple, because it either returns a resolved promise, or never resolves the promise. In both cases it creates a promise and hands it back to the user.
>>
>> In the next step I need to vend a promise that I will resolve later--possibly never.
>
>
> Is there some point at which you know that you'll never resolve the promise? That's the point at which to break the cycle. For example, we typically break these cycles when the ActiveDOMObject::stop notification is called.I think it is the frame navigating. So navigator.serviceWorker, which is already a ContextLifecycleObserver, should simply use that as a signal to relinquish the Promise handles?
> One difficulty with using weak processing to define the point at which the promise will never resolve is that we'll leak some implementation details about when we trigger garbage collection.
Leak implementation details to whom?
On Jun 10, 2014 8:57 AM, "Adam Barth" <aba...@google.com> wrote:
>
> On Tue Jun 10 2014 at 8:50:19 AM, Dominic Cooney <domi...@google.com> wrote:
>>
>> On Jun 10, 2014 8:09 AM, "Adam Barth" <aba...@google.com> wrote:
>> > On Mon Jun 09 2014 at 10:52:53 PM, 'Dominic Cooney' via blink-dev <blin...@chromium.org> wrote:
>> >>
>> >> I think I need a cycles-defeating promise, something like a ScriptPromise with a weak handle and an hidden property from wrapper to promise. Can you give me some implementation pointers?
>> >>
>> >> Here's my situation:
>> >>
>> >> I have an object, navigator.serviceWorker, that vends promises through a "ready" property.
>> >>
>> >> The implementation today is very simple, because it either returns a resolved promise, or never resolves the promise. In both cases it creates a promise and hands it back to the user.
>> >>
>> >> In the next step I need to vend a promise that I will resolve later--possibly never.
>> >
>> >
>> > Is there some point at which you know that you'll never resolve the promise? That's the point at which to break the cycle. For example, we typically break these cycles when the ActiveDOMObject::stop notification is called.
>>
>> I think it is the frame navigating. So navigator.serviceWorker, which is already a ContextLifecycleObserver, should simply use that as a signal to relinquish the Promise handles?
>
> You probably need to upgrade from ContextLifecycleObserver to ActiveDOMObject. The problem with using the contextDestroyed notification is that holding the promise might prevent the context from being destroyed.
Of course. Thanks for the pointers.
The spec for ready says it can resolve with different objects over the lifetime of the page (for example, after replace) so it is sometimes necessary to return a new promise.
I can make Blink return as few as possible. FWIW I don't think I have seen this as a *requirement*.
> --
> http://annevankesteren.nl/
My original post was about another ready, ServiceWorkerContainer.ready, which I think is Promise<ServiceWorker> IIRC.