sugarcube-3 icon indicating copy to clipboard operation
sugarcube-3 copied to clipboard

Asynchronicity and user APIs

Open tmedwards opened this issue 4 years ago • 7 comments

One of SugarCube v3's, aspirational, goals is to enable the use of IndexedDB as a storage provider. Unfortunately, since IndexedDB only offers an asynchronous API, this has consequences for any SugarCube API that provides or depends on storage.

Internally, this isn't an issue. For user facing APIs, however, this could have serious consequences. For example, the recall() API would be seriously changed by this:

// Current synchronous usage.
<<set $foo to recall('foo', 'bar')>>

// Asynchronous usage directly using the returned `Promise`.
<<set recall('foo', 'bar').then(value => $foo to value)>>

That's not a change that I think most users would be happy to see—the non-technical ones, at the very least.

Try to find a solution or workaround for this that's more user friendly.

EDIT: Addendum

There's also the possibility of using await, however, that's only slightly less bad for users. Assuming it could be made to work in the context it would execute within in the first place.

// Asynchronous usage `await`'ing the returned `Promise`.
<<set $foo to await recall('foo', 'bar')>>

tmedwards avatar Feb 20 '21 17:02 tmedwards