Skip to content

Instantly share code, notes, and snippets.

@esnya
Last active February 12, 2016 00:07
Show Gist options
  • Save esnya/1eefe07f8ce78d330216 to your computer and use it in GitHub Desktop.
Save esnya/1eefe07f8ce78d330216 to your computer and use it in GitHub Desktop.
Promiseコード片
let hoge = null;
const getHoge = () => hoge
? Promise.resolve(hoge)
: new Promise((resolve, reject) => {
someAsnycWork((data) => {
hoge = data;
resolve(data);
})
});
export const doHoge = () =>
getHoge()
.then((hoge) => (someWorkWithHoge(hoge)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment