- From: Benjamin Gruenbaum <notifications@github.com>
- Date: Tue, 18 Jul 2017 15:42:55 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Tuesday, 18 July 2017 22:43:22 UTC
The following also works with fetch: ```js async function getResource(onCancel) { var controller = new FetchController(), signal = controller.signal; onCancel(() => controller.abort()); var result = await fetch("./someResource", {signal}).then(req => req.text()); return process(result); } // outside var cancel; var resourcePromise = getResource(fn => cancel = fn); onExternalEventThatCausesCancellation(() => { cancel(); // calls .abort on the fetch controller. }); // Or: var resource = await getResource(onExternalEventThatCausesCancellation); ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/447#issuecomment-316219229
Received on Tuesday, 18 July 2017 22:43:22 UTC