[webkit-dev] Web SQL Database API - openDatabaseSync

Evan Ireland eireland at sybase.com
Thu Jul 8 14:58:37 PDT 2010


The asynchronous API makes composition much more difficult. Like if we
generate code that wraps the database API into business objects, all the
business object methods need to accept callback parameters.

Suppose I want to show an employee together with their department name, I
could write:

function formatEmployee(e)
    return e.getName() + ", " + e.getDepartment().getName();

Forgive my using "alert", just for the purpose of example.

Now suppose that e.getDepartment() call (child to parent navigation) needs
to be asynchronous due to lazy loading.

Now I need something like:

function formatEmployee(e, success, failure)
            success(e.getName() + ", " + d.getName());
            function(s) { alert(s); },
            function() { /* ignore failure */ }
    function() { /* ignore failure */ }

Is soon gets very nasty. I do appreciate how to program in a
continuation-passing style, which can be easier with good language support
(e.g. Haskell). But just imagine if the '+' operator was asynchronous, how
much more trouble ordinary programming would be.

In any case, I can accept that using synchronous DB API in the UI thread
could be considered undesirable.
Using it from a worker thread however is essential. To get good
composability, I might wish to run business objects in a worker thread using
a synchronous API rather than using an asynchronous API from the UI thread.

I hope this helps to clarify where I am coming from with my questions.

-----Original Message-----
From: Dmitry Titov [mailto:dimich at google.com] 
Sent: Thursday, July 08, 2010 2:27 PM
To: Evan Ireland
Cc: Andrei Popescu; Eric Uhrhane; webkit-dev at lists.webkit.org
Subject: Re: [webkit-dev] Web SQL Database API - openDatabaseSync

On Tue, Jul 6, 2010 at 10:00 AM, Evan Ireland <eireland at sybase.com> wrote:

> Andrei,
> On page:
>  http://www.ibm.com/developerworks/library/x-html5mobile4/
> I see:
>  "Starting with Android 2.0, the Android browser has had full support for
> the HTML 5 Web Worker specification."
> Is the quoted page incorrect about Web Workers on Android? (It seems to
> contradict what you wrote below).
> I was hoping to do some prototyping with Web Workers and Google Gears on
> Android until such time as the sync database API is available. But perhaps
> I
> will need to limit testing to desktop Chrome for the moment.

I'd be curious what benefit the synchronous version of API gives? Isn't it
useful to keep even the workers responsive to PostMessage from UI thread, as
opposite to accumulating a ton of posted messages and then receiving them in
a rapid-fire in the worker after a sync API returns? What if it never
returns (the database is locked or who knows)? I don't know what you are
building of course, but using async code everywhere doesn't look like a
terrible choice. Or does it? :-) Just curious.

> -----Original Message-----
> From: Andrei Popescu [mailto:andreip at google.com]
> Sent: Friday, July 02, 2010 3:54 AM
> To: Eric Uhrhane
> Cc: Evan Ireland; webkit-dev at lists.webkit.org
> Subject: Re: [webkit-dev] Web SQL Database API - openDatabaseSync
> Hi,
> On Fri, Jul 2, 2010 at 2:40 AM, Eric Uhrhane <ericu at google.com> wrote:
> > I doubt that it's been pushed to any Android phone yet.  It only went
> > into webkit in the past couple of months, and there's a bit of lag as
> > they incorporate new code.  You'd have to ask Android folks when they
> > plan to ship it.
> >
> Async Web SQL Database is available on Android since version 2.0.
> Sync Web SQL Database and Web Workers are not currently available on
> Android (not even on 2.2).
> Thanks,
> Andrei
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

More information about the webkit-dev mailing list