Skip to content

Instantly share code, notes, and snippets.

@xryuseix
Last active May 13, 2020 06:02
Show Gist options
  • Save xryuseix/49a4f7fad7817e3532c8e596d9f99491 to your computer and use it in GitHub Desktop.
Save xryuseix/49a4f7fad7817e3532c8e596d9f99491 to your computer and use it in GitHub Desktop.
function storageGet() {
var res;
chrome.storage.local.get(res = callbackFunc(items));
console.log(res);
return res;
}
function callbackFunc(items) {
console.log(items);
callback(items);
}
const items = storageGet();
@ygkn
Copy link

ygkn commented May 12, 2020

三つ目の,はこんな感じ...

function storageGet() {
  return new Promise((resolve) => chrome.storage.local.get((items) => resolve));
}

async function postPlayLists() {
  const playlists = await storageGet();
  console.log(playlists); // エラーも何も表示されない
}
 function storageGet() {
-  return new Promise((resolve) => chrome.storage.local.get((items) => resolve));
+  return new Promise((resolve) => chrome.storage.local.get((items) => resolve(items)));
 }

やったわテヘペロ

@xryuseix
Copy link
Author

xryuseix commented May 12, 2020

new Promise((resolve) => chrome.storage.local.get((items) => resolve));
+  return new Promise((resolve) => chrome.storage.local.get((items) => resolve(items)));
}

やったわテヘペロ

できた!!!ありがとう!!

console.log(playlists); はちゃうな〜

これは,どうしたらよかったの??

@ygkn
Copy link

ygkn commented May 13, 2020

普通に

function postPlayLists() {
  const playlists = storageGet(() => { /* なんかする */});
}

やで

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment