Skip to content

Instantly share code, notes, and snippets.

@ai
Created August 12, 2019 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ai/fa3999b22a680f315ba2382b8c4c50b4 to your computer and use it in GitHub Desktop.
Save ai/fa3999b22a680f315ba2382b8c4c50b4 to your computer and use it in GitHub Desktop.
// Глобальный счётчик запросов
let lastRequest = 0
export function send (...args, callback) {
// Запоминаем какой номер у этого запроса
const thisRequest = ++lastRequest
fetch(...args).then(responce => {
// Игнорируем ответ, если номер этого запроса
// не совпадает с номером последнего
if (thisRequest !== lastRequest) return
callback(responce)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment