Last active
October 6, 2016 07:17
-
-
Save aloerina01/13fa540af3b6d750f69811c2d6507e81 to your computer and use it in GitHub Desktop.
キャッシュから取得/サーバから取得 を楽に書く方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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