Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Last active March 24, 2016 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhrrgn/785ad516304b89448167 to your computer and use it in GitHub Desktop.
Save dhrrgn/785ad516304b89448167 to your computer and use it in GitHub Desktop.
function asyncMultiGet(keys) {
return AsyncStorage.multiGet(keys)
.then((err, data) => {
if (! err) {
return data.reduce(function (carry, val) {
carry[val[0]] = val[1];
return carry;
}, {});
}
// TODO Handle errors
});
}
// Usage
asyncMultiGet(['key1', 'key2'])
.then((data) => {
// {"key1": "value1", "key2": "value2"}
console.log(data);
});
// This becomes even easier if you use async/await:
let data = await asyncMultiGet(['key1', 'key2']);
// {"key1": "value1", "key2": "value2"}
console.log(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment