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 MaynardReceived on Thursday, 10 February 2011 02:13:19 UTC
This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:16 UTC