inexorabletash / indexeddb-promises

Proposal for incremental support for Promises in the Indexed DB API
48 stars 2 forks source link

Better name for IDBRequest's promise getter? #4

Closed inexorabletash closed 9 years ago

inexorabletash commented 9 years ago

Currently .promise.

@domenic suggests .ready, .complete, .done but has no preferences

inexorabletash commented 9 years ago

I don't like .promise either. To list the other stuff on IDBRequest, we're competing with:

My concern about .ready, .complete or .done specifically is that the promise holds the result value, not just the signal that the request is complete (unlike on the transaction), and thus accessing the value with those will read awkwardly with await syntax.

Oooooh... how about .value ?

let x = await store.get(key).value;
let count = await store.count(range).value;
let cursor = await index.openCursor().value;

Possible objection: IDBCursor has .value as a synchronous accessor (along with .key etc)

inexorabletash commented 9 years ago

.value is also a bit odd for put calls when the result isn't actually used, e.g.

await store.put(data).value;
...
jakearchibald commented 9 years ago

My concern about .ready, .complete or .done specifically is that the promise holds the result value, not just the signal that the request is complete

I think this is fine. navigator.serviceWorker.ready resolves with a registration, .ready in the font loading API resolves with a font face object.

inexorabletash commented 9 years ago

Done - .ready it is.