Closed waltfy closed 9 years ago
I think the best approach here would be to cancel the in-flight request A
before B
is sent. You could do this with a stateful plugin:
class PathPrefixFilter { ... }
class OneRequestInFlightPlugin {
willFetch() {
if (this.cancelCurrent) {
this.cancelCurrent();
delete this.cancelCurrent;
}
}
fetch({ cancel }) {
this.cancelCurrent = cancel;
}
}
var fetch = new FetchEngine({
plugins: [
new FetchPreset({
filters: [ new PathPrefixFilter('/search') ],
plugins: [ new OneRequestInFlightPlugin() ]
})
]
});
This is slightly fiddly becuase the response handling code will have to handle cancellations... but then it probably should be handling failures already.
Closing, will come back to this use-case when there's an implementation.
@phuu Makes sense. Thanks!
What would a plugin that cancels all but the most recent request look like? Imagining the following scenario:
Then imagine the following sample flow:
There are various ways of solving this problem, most involve performing some reconciliation within the response handler — to decide whether the results list should be updated.
I am wondering what a plugin that cancels all but the most recent request, would look like?
Loving the work so far, think it adds a lot of value to complex data fetching.