Skip to content

Instantly share code, notes, and snippets.

@ajcastro
Last active June 9, 2019 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajcastro/73363f737b27890b0d5aa9e88f872a8e to your computer and use it in GitHub Desktop.
Save ajcastro/73363f737b27890b0d5aa9e88f872a8e to your computer and use it in GitHub Desktop.
import axios from 'axios'
export default class Cancellable {
constructor(cancelMessage) {
this.cancelMessage = cancelMessage
this.cancelToken = null
}
axios(fn) {
if (this.cancelToken) {
this.cancelToken.cancel(this.cancelMessage)
this.cancelToken = null
}
this.cancelToken = axios.CancelToken.source()
fn(this.cancelToken)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment