forwardemail / forwardemail/superagent
Abort seems not working properly
- Dominant language
- JavaScript
- Stars
- 16.6k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
I am currently using superagent with saga and like to keep using it
here is some code I have been trying. somehow promise.abort is undefined even though I can see a lot of request is on pending on the dev tool.
When I tried to pass promise to the redux and abort in there. It only cancel first pending request somehow.
```
yield put(getSearchActions.request({ payloadJson }))
if(fetching && promise && promise.abort) {
console.log(' I am aborting')
promise.abort()
}
promise = apiSearch({ data: payload })
const result = yield promise
yield put(getSearchActions.success(payload, result.response))
promise = null
return null
```
However, I tried with axios. this code actually cancelling. With axios I found out I need to generate cancelToken after I cancel. Do I have to do the similar thing with superagent?
```
if(fetching) {
source.cancel()
source = CancelToken.source()
}
yield put(getSearchActions.request({ payloadJson }))
yield delay(200)
try {
const result = yield instance.get('/url', {
params: payload,
cancelToken: source.token,
})
yield put(getSearchActions.success(payload, { data: result.data }))
} catch(e) {
console.log(e)
yield put(getSearchActions.failure(payload, null))
}
```
Contributor guide
Assessment
This issue has not been assessed yet.