Skip to content

Instantly share code, notes, and snippets.

@bartlomieju
Created October 28, 2019 15:30
Show Gist options
  • Save bartlomieju/451f0089d3d63a3bfd1b5c756e026877 to your computer and use it in GitHub Desktop.
Save bartlomieju/451f0089d3d63a3bfd1b5c756e026877 to your computer and use it in GitHub Desktop.
Deno CLI resources

CLI things that should be resources:

  • global_timer
  • start_time
  • other timers
  • metrics? (it'd be nice if they were resources, but I fear it might be slow because of double lookup for each op)

Problems with refactor:

  • no way for full polymorphism Tried with StreamResource enum:

    pub enum StreamResource {
      Read(Box<dyn DenoAsyncRead>),
      Write(Box<dyn DenoAsyncWrite>),
      ReadWrite(Box<dyn DenoAsyncReadWrite>),
    }

    Managed to get io to work (read/write) but can't cast it to concrete type if another operation is needed. Eg. shutdown for TcpStream. Can revert to CliResource enum but that doesn't play nicely with splitting ops to separate crates.

  • need to untangle worker resource It's used in numerous places - cli/state.rs, cli/worker.rs, cli/ops/workers.rs. It might make more sense to do denoland/deno#3116 before resources.

  • move as much stuff as possible from ThreadSafeState

  • dependent op modules

    • on io (AsyncRead/AsyncWrite):
      • fs
        • file
      • tls
        • client tls stream
        • server tls stream
      • net
        • tcp stream
      • process
        • child stdin
        • child stdout
        • child stderr
      • fetch
        • http body
      • no crate
        • stdin
        • stdout
        • stderr
    • on net
      • tls
        • server tls stream
    • process
      • fs
        • using file as stdout/stderr for process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment