Skip to content

Allow queued earcut work to be discarded when its layer is finalized #227

Description

@jsve

A polygon layer can be finalized while its earcut task is still waiting in a shared worker pool—for example, when a viewport changes or a progressive Arrow response is replaced before every record-batch layer finishes triangulating.

finalizeState() correctly avoids terminating an externally owned pool, but the obsolete layer’s queued task remains. It can later consume worker time and allocate or transfer geometry even though its result can no longer be displayed.

Would it be possible for the layer to retain ownership of its queued task and discard it during finalization if it has not started yet, without terminating the shared pool?

This could use the pool’s task handle, an abort signal, or another internal mechanism. The important semantics would be:

  • Finalizing one layer must not terminate or disrupt a shared pool.
  • Work that has not started should be removed from the queue.
  • Any promise awaited by the layer must settle cleanly rather than being left pending.
  • Already-running worker jobs do not necessarily need to be interrupted; cancelling those safely is a separate and harder problem.

This would complement #225: moving payload preparation inside the worker task prevents a cancelled queued job from cloning its geometry before it starts.

A possible regression test would use a one-worker pool, hold its first task open, queue triangulation for a second layer, finalize that second layer, and verify that its worker callback never runs while the first task and the shared pool continue normally.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions