Skip to content

Task vs Resource & RxJS

Choosing the right reactive primitive is essential for clean Angular architecture.

1. Task vs Resource / rxResource

Angular 19+ introduces resource() and rxResource() for declarative data loading. Here is how ngx-task compares:

Feature / IntentResource (resource / rxResource)Task (ngx-task)
Primary IntentDeclarative Data Fetching (Read)Imperative Action / Command (Write/Execute)
Trigger MechanismReactive signal dependency changesUser gesture (click, submit, explicit .run())
Typical Use CasesFetching user profile by userId(), loading page dataForm submission, Login, Payment checkout, File upload, Autosave
Concurrency PoliciesAutomatic restart on signal changeExplicit policies: drop, restart, enqueue, latest, parallel
Visual Timing ControlsNoneBuilt-in pendingDelay & minimumPendingDuration anti-flicker
Progress ReportingNot supportedBuilt-in progress tracking via context.reportProgress()
Retries & Attempt CounterManual reloadretryLast() and context.attempt counter

2. Task vs RxJS Flattening Operators

In traditional Angular applications, developers use RxJS Subject streams combined with flattening operators (exhaustMap, switchMap, concatMap, mergeMap) to control concurrency.

Here is how ngx-task policies map to RxJS operators:

ngx-task PolicyEquivalent RxJS OperatorKey Advantage of ngx-task
dropexhaustMapExposes signals (pending, running), anti-flicker, automatic component cleanup
restartswitchMapAutomatic AbortSignal cancellation for Promises & Observables
enqueueconcatMapQueue limit & overflow policy controls (maxQueueSize, overflowPolicy)
latestCustom buffer(1) / switchMapSkips intermediate queued items, keeping only newest
parallelmergeMap(..., limit)Concurrent execution limit signals & individual TaskExecution handles

Why use ngx-task instead of manual RxJS subjects?

  1. No Manual Subject Boilerplate: No need to create Subject, pipe operators, subscribe, or manage subscriptions.
  2. First-Class Signal API: Direct consumption in Angular templates without toSignal() or async pipe.
  3. Comprehensive Lifecycle & State: Exposes running counts, queue counts, progress, attempt counters, and execution handles out of the box.