store.js icon indicating copy to clipboard operation
store.js copied to clipboard

has asynchronous function?

Open junhui75165 opened this issue 7 years ago • 4 comments

something like promise .then

junhui75165 avatar May 23 '17 01:05 junhui75165

Can you write out a piece of example code that shows what you'd like to be able to do please?

marcuswestin avatar Jun 17 '17 18:06 marcuswestin

AFAIK, most storage mechanisms are synchronous so I'm not sure that exposing an async method would be safe. However, the following is probably what was intended:

import * as store from "store"

store.set("some_key", "some_keyed_value");

store.get("some_key")
    .then(value => { 
        console.log(value); 
        /* Should print 'some_keyed_value' to console */
    });

ghost avatar Oct 03 '17 01:10 ghost

This doesn't really make sense. Why would a read from localstorage by asynchronous?

genu avatar Aug 26 '18 17:08 genu

@genu Agreed, but there are async storage APIs out there which store.js could handle if it had an async capability. Although deprecated, WebSQL is an example of an async storage API, there may be others these days, but it's been a while since I looked.

ghost avatar Aug 28 '18 22:08 ghost