PriorityStrategy

public enum PriorityStrategy

Defines the overall task execution order and priority handling strategy.

This is the primary control for task scheduling behavior and significantly affects both performance characteristics and resource usage patterns.

Choosing the Right Strategy

  • FIFO: Use for batch processing, fair resource allocation, or when task order matters
  • LIFO(.await): Use for responsive systems with predictable task completion
  • LIFO(.stop): Use for highly interactive systems with dynamic priorities
  • First In, First Out - tasks execute in submission order.

    Characteristics:

    • Fair resource allocation across all submitted tasks
    • Predictable execution order regardless of timing
    • No task interruption or complex state management
    • Consistent performance characteristics

    Ideal use cases:

    • Batch processing systems where order matters
    • Background processing where fairness is important
    • Systems with relatively uniform task priorities
    • Operations where interruption would be problematic

    Declaration

    Swift

    case FIFO
  • Last In, First Out - most recent tasks get priority.

    Characteristics:

    • Recent tasks are prioritized over older submissions
    • Supports both non-interrupting (.await) and interrupting (.stop) modes
    • Better responsiveness for user-initiated operations
    • More complex resource management and state handling

    Ideal use cases:

    • Interactive applications where recent requests matter most
    • Systems with dynamic priority requirements
    • User-facing operations that should feel responsive
    • Scenarios where newer data/requests invalidate older ones

    Declaration

    Swift

    case LIFO(LIFOStrategy)

    Parameters

    strategy

    How to handle resource conflicts with running tasks