Skip to content

Investigate use of futures/stream/async in Fetch #22813

Open

Description

@gterzian

A "fetch" currently looks like:

  1. Spawn a thread to run fetch.
  2. Ask the cache for a cached response
  3. If the cached returned a cached, yet still ongoing response, wait for the cached response to finish.
  4. If the cache couldn't construct a response, do a [network fetch](
    fn http_network_fetch(
    .
  5. Wait for the network fetch to complete.

Note that the network fetch already uses a Tokio runtime to obtain the response and then handle the response.

In all cases where either the network or cached response is "awaited", this DoneChannel is used to signal that the response is ready, or cancelled.

It appears to me that the thread spawned at 1 above could be replaced with a(or several) Future, or maybe Stream, and that the entire workflow could be modeled with it. The "done channel" could also be replaced with a task-aware channel.

This is probably a better solution to the problem of "one thread per fetch" noted here #22768

Activity

  1. added 9 commits that reference this issue on Dec 18, 2021
  2. added a commit that references this issue on Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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