Skip to content

AbortSignal on requests #1775

@rickmcgeer

Description

@rickmcgeer

Describe the Feature
The standard five-minute timeout on fetch is far too long for most uses; we should have a method for making it much faster than that. All modern browser support an AbortSignal https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal with a timeout, which is used as

fetch(url, { signal: AbortSignal.timeout(5000) });

However, as nearly as I can tell resource doesn't expose that. See:

$world.execCommand("open browser", {moduleName: "src/http-resource.js", packageName: "lively.resources", codeEntity: "makeRequest"});

In fact, the only fetch options directly exposed is the method: const fetchOpts = { method }; though others are set from resource attributes

Graphics
If applicable, provide screenshots/videos of similar ideas in other software.

Implementation Details
I suggest either:
(1) Adding a timeout option to resource

$world.execCommand("open browser", {moduleName: "src/resource.js", packageName: "lively.resources", codeEntity: "Resource"});

And the following code to makeRequest

 var { useCors, useProxy, timeout, headers: moreHeaders } = resource;
...
if (!isNaN(tmeout) fetchOpts.signal= AbortSignal.timeout(timeout);

Or
(2) Exposing a fetchOptions attribute directly in Resource or as a parameter to makeRequest

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions