Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiGet support ? #7

Open
dungnguyen10989 opened this issue Nov 26, 2018 · 1 comment
Open

MultiGet support ? #7

dungnguyen10989 opened this issue Nov 26, 2018 · 1 comment

Comments

@dungnguyen10989
Copy link

Hi!
Can you provide the method MultiGet like 'react-native/AsyncStorage' ?

@woodpav
Copy link

woodpav commented Feb 8, 2019

Be warned: You must use SecureStorage sequentially.

This function does not work:

async function multiGet(keys) {
  return await Promise.all(keys.map(SecureStorage.getItem));
}

Use this function instead:

async function multiGet(keys) {
  var acc = {};
  for (var key of keys) {
    await new Promise((res, rej) => setTimeout(res, 100));  // sleep for 100ms
    acc[key] = await SecureStorage.getItem(key);
  }
  return acc;
}

Edit: this applies to getItem and removeItem and may apply to getAllKeys and setItem as well.

Edit 2: it looks like SecureStorage functions cannot be fired in quick succession. There needs to be a delay added.

Edit 3: I suggest using JSON.stringify to store multiple keys if at all possible to avoid the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants