marcuswestin / store.js

Cross-browser storage for all use cases, used across the web.
MIT License
14.02k stars 1.33k forks source link

has asynchronous function? #234

Open junhui75165 opened 7 years ago

junhui75165 commented 7 years ago

something like promise .then

marcuswestin commented 7 years ago

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

ghost commented 7 years ago

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 */
    });
genu commented 6 years ago

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

ghost commented 6 years ago

@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.