From d939f2ffbcb632361a0362f0f2049f99160dee64 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 21:08:06 +0300 Subject: [PATCH] document makeFetcher a bit --- src/services/fetcher/fetcher.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js index 95b8c9d32d..5a6ed4b8e1 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/fetcher/fetcher.js @@ -1,11 +1,17 @@ -export const makeFetcher = (call, interval) => { +// makeFetcher - replacement for setInterval for fetching, starts counting +// the interval only after a request is done instead of immediately. +// promiseCall is a function that returns a promise, it's called when created +// and after every interval. +// interval is the interval delay in ms. + +export const makeFetcher = (promiseCall, interval) => { let stopped = false let timeout = null let func = () => {} func = () => { - call().finally(() => { + promiseCall().finally(() => { if (stopped) return timeout = window.setTimeout(func, interval) })