LIFOStrategy

public enum LIFOStrategy

Defines how new tasks handle currently running tasks in LIFO priority mode.

This strategy only applies when using PriorityStrategy.LIFO(strategy) and determines the behavior when a new high-priority task needs resources that are currently in use.

Performance Characteristics

  • .await: Lower interruption overhead, predictable completion times
  • .stop: Higher responsiveness, potential task restart overhead

Memory Implications

  • .await: Gradual memory usage patterns, no sudden spikes
  • .stop: Potential memory spikes from simultaneous task states
  • New tasks wait for currently running tasks to complete naturally.

    Behavior: When a new high-priority task is added, it joins the queue and waits for running tasks to finish before starting execution.

    Best for:

    • Scenarios where task interruption is expensive or problematic
    • Operations that don’t handle interruption gracefully
    • Systems where predictable completion times are more important than responsiveness
    • Tasks with complex state that’s difficult to preserve across interruptions

    Trade-offs:

    • ✅ No interruption overhead or complexity
    • ✅ Guaranteed task completion without restarts
    • ✅ Simpler debugging and monitoring
    • ❌ Lower responsiveness for high-priority tasks
    • ❌ Potential priority inversion in some scenarios

    Declaration

    Swift

    case await
  • New tasks stop currently running tasks to start immediately.

    Behavior: When a new high-priority task is added, it immediately stops one or more running tasks, moves them to the waiting queue, and starts execution. Stopped tasks are automatically restarted when resources become available.

    Best for:

    • Interactive applications where responsiveness is critical
    • Tasks that support efficient state preservation and resumption
    • Scenarios with clear priority hierarchies (user-initiated vs background tasks)
    • Operations where recent requests are more valuable than older ones

    Trade-offs:

    • ✅ Maximum responsiveness for high-priority tasks
    • ✅ Better resource utilization in dynamic priority scenarios
    • ✅ Natural handling of priority changes during execution
    • ❌ Additional complexity from task interruption and resumption
    • ❌ Potential efficiency loss from task restarts (if using .dealloc)
    • ❌ More complex debugging due to task state transitions

    Declaration

    Swift

    case stop