Skip to content

CompilePdfAsync compiles synchronously; the CancellationToken only covers the write #43

Description

@msallin

CompilePdfAsync(string outputFile, ..., CancellationToken) (TypstCompiler.cs:420):

using var document = CompileToDocument("pdf", pdfStandards: pdfStandards);
await document.WriteOutputToFileAsync(outputFile, cancellationToken: cancellationToken).ConfigureAwait(false);

CompileToDocument is a blocking P/Invoke, so the compile runs synchronously on the calling thread before the first await, and the token reaches only the file write. The stream overload (:453) has the same shape. The XML doc says "Asynchronously compiles the Typst document".

Two consequences. The async overloads hold a thread-pool thread for the whole compile instead of yielding, so callers who chose them to avoid that get no benefit. And a cancelled request reclaims nothing: RequestAborted or a Kestrel timeout fires, the token is observed only after the compile has finished, and the work runs to completion. Typst caps while at 10,000 iterations but not for over a large range, so the duration is unbounded.

What I would like:

  1. Correct the XML docs and README: compilation is synchronous and CPU-bound, the async overloads cover only the output write, and the token does not cancel the compile.
  2. An overload that runs the compile on the thread pool and honours the token before starting, so the caller's thread is released.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions