Skip to content

Instantly share code, notes, and snippets.

@shapkarin
Last active June 22, 2019 14:25
Show Gist options
  • Save shapkarin/5dfb7dd134fca1e51fdcef1fd24a8adf to your computer and use it in GitHub Desktop.
Save shapkarin/5dfb7dd134fca1e51fdcef1fd24a8adf to your computer and use it in GitHub Desktop.
Close axios with saga worker cancellation. thank's to that issue https://github.com/redux-saga/redux-saga/issues/651
import axios, { CancelToken } from 'axios';
import { CANCEL } from 'redux-saga';
export const fetchAutocomplete = () => {
const url = 'some/url';
const source = CancelToken.source();
const request = axios.get(url, { cancelToken: source.token });
request[CANCEL] = () => source.cancel();
return request;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment