commit 4cad6f73c05ff60e570797a07f585cb40c1511d7
parent 6af02afd8757f3901f0bc8bcad75c87fa9a3b57e
Author: Konstantin Tarkus <hello@tarkus.me>
Date: Mon, 7 Mar 2016 13:45:34 +0300
Use bluebird Promise library in src/core/fetch/fetch.server.js
Diffstat:
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/core/fetch/fetch.server.js b/src/core/fetch/fetch.server.js
@@ -7,9 +7,12 @@
* LICENSE.txt file in the root directory of this source tree.
*/
+import Promise from 'bluebird';
import fetch, { Request, Headers, Response } from 'node-fetch';
import { host } from '../../config';
+fetch.Promise = Promise;
+
function localUrl(url) {
if (url.startsWith('//')) {
return `https:${url}`;
diff --git a/src/data/queries/news.js b/src/data/queries/news.js
@@ -26,7 +26,7 @@ const news = {
return lastFetchTask;
}
- if ((new Date() - lastFetchTime) > 1000 * 60 * 10 /* 10 mins */) {
+ if ((new Date() - lastFetchTime) > 1000 * 3 /* 10 mins */) {
lastFetchTime = new Date();
lastFetchTask = fetch(url)
.then(response => response.json())
@@ -36,8 +36,15 @@ const news = {
}
return items;
+ })
+ .finally(() => {
+ lastFetchTask = null;
});
+ if (items.length) {
+ return items;
+ }
+
return lastFetchTask;
}