Skip to content

Instantly share code, notes, and snippets.

@aloerina01
Last active October 6, 2016 07:17
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 aloerina01/13fa540af3b6d750f69811c2d6507e81 to your computer and use it in GitHub Desktop.
Save aloerina01/13fa540af3b6d750f69811c2d6507e81 to your computer and use it in GitHub Desktop.
キャッシュから取得/サーバから取得 を楽に書く方法
export default class RequestService {
getAsync(groupId) {
return new Promise.race([
this._getFromCache(groupId),
this._getFromServer(groupId)
]);
}
_getFromCache(groupId) {
return new Promise((resolve, reject) => {/* (A) */})
.then((res) => {/* (B) */});
}
_getFromServer(groupId) {
return new Promise((resolve, reject) => {/* (C) */})
.then((res) => {/* (D) */});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment