W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2011

Re: [IndexedDB] setVersion blocked on uncollected garbage IDBDatabases

From: Glenn Maynard <glenn@zewt.org>
Date: Wed, 9 Feb 2011 21:12:47 -0500
Message-ID: <AANLkTimWDWQpxPkqCwau0Bo08P8XWJ9GY8K-JQK4TKbU@mail.gmail.com>
To: Jonas Sicking <jonas@sicking.cc>
Cc: Drew Wilson <atwilson@google.com>, Jeremy Orlow <jorlow@chromium.org>, ben turner <bent.mozilla@gmail.com>, João Eiras <joao.eiras@gmail.com>, public-webapps <public-webapps@w3.org>
On Wed, Feb 9, 2011 at 8:39 PM, Jonas Sicking <jonas@sicking.cc> wrote:

> On Wed, Feb 9, 2011 at 5:26 PM, Glenn Maynard <glenn@zewt.org> wrote:
> > Another related issue: what happens if a long-running number-cruncher
> worker
> > keeps a database open while it works, to read data or output results?
> > There's no API for sending versionchange events for IDBDatabaseSync, and
> it
> > doesn't fit in any obvious way since it's inherently asynchronous.  I
> > suppose the developer-side workaround would be to open the same database
> > asynchronously in the UI thread just to listen for versionchange, and to
> > terminate the thread when it's received.  Is that generally what's
> intended?
>
> This is a good point. We should add the ability to dispatch
> versionchange events on IDBDatabaseSync. There is no reason we
> couldn't just make it a event target and add a .onversionchange
> property to it.
>
> Just because the object has some (or many, or only) synchronous
> methods, doesn't mean it can't also dispatch events.
>

That works provided your worker periocally returns to the caller, to allow
events to be dispatched; otherwise the event will never be received.  That's
usually the case--even for number-crunching workers, most use cases look
like "receive a request, spend a few seconds doing calculations and I/O and
return the result".

Not all do--some number-crunching cases might take minutes to run.  The
typical example is expensive renderers, such as a raytracer that may take a
couple minutes to render a scene.  These sorts of tasks wouldn't want to
return to the caller--being able to write these algorithms linearly rather
than in an incremental, setTimeout-based fashion is a basic use case of
workers.  That said, these are uncommon enough that it's the "asynchronous
watcher in a separate thread" workaround seems acceptable.

(That's also another case where the API discussed in the "synchronously
handling events" thread would become useful: you could send a message to the
thread while it's running, without needing to terminate it outright.)

-- 
Glenn Maynard
Received on Thursday, 10 February 2011 02:13:19 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:43 GMT