Skip to content

Configuration values ​

Most constructors in @haskou/flow accept plain numbers for convenience. Numbers that represent time are interpreted as milliseconds.

When you want stronger names in application code, you can pass explicit configuration values instead. They are especially useful when a value is created once and reused across several queues, schedulers, flows, or circuit breakers.

Import ​

typescript
import {
  Concurrency,
  RateLimiterInterval,
  RetryAttempts,
  RetryDelay,
  TimeoutDuration,
} from '@haskou/flow';
import { Duration } from '@haskou/value-objects';

Common examples ​

Concurrency ​

typescript
import { Concurrency, Queue, QueueOptions } from '@haskou/flow';

const concurrency = new Concurrency(4);
const queue = new Queue(QueueOptions.withConcurrency(concurrency));

Time values ​

typescript
import {
  RateLimiterInterval,
  RateLimiterOptions,
  Timeout,
  TimeoutDuration,
} from '@haskou/flow';
import { Duration } from '@haskou/value-objects';

const rateLimiterOptions = new RateLimiterOptions(
  new RateLimiterInterval(Duration.fromMilliseconds(100)),
);

const timeout = new Timeout(new TimeoutDuration(Duration.fromSeconds(3)));

Retry values ​

typescript
import { Retrier, RetryAttempts, RetryDelay, RetryOptions } from '@haskou/flow';
import { Duration } from '@haskou/value-objects';

const retrier = new Retrier(
  new RetryOptions(
    new RetryAttempts(3),
    new RetryDelay(Duration.fromMilliseconds(50)),
  ),
);

Concurrency values ​

ClassUsed byMeaning
ConcurrencyQueueOptions, CircuitBreakerOptionsMaximum active work allowed.
SemaphoreCapacitySemaphoreTotal number of semaphore permits.

Timing values ​

ClassUsed byMeaning
RateLimiterIntervalRateLimiterOptionsMinimum spacing between reserved task starts.
SchedulerIntervalSchedulerOptionsDelay between scheduler ticks.
DebounceDelayDebouncerQuiet period before the latest task runs.
ThrottleIntervalThrottlerMinimum spacing between throttled task starts.
TimeoutDurationTimeout, Flow.timeout()Maximum duration allowed before timeout.
CircuitBreakerRecoveryTimeoutCircuitBreakerOptionsHow long an open circuit breaker waits before half-open probing.
RetryDelayRetryOptionsDelay between retry attempts.

Retry values ​

ClassUsed byMeaning
RetryAttemptsRetryOptionsTotal attempts before the last error is rethrown.
RetryAttemptCountRetrier internalsCurrent attempt count. Exported for advanced integrations.

Circuit breaker values ​

ClassUsed byMeaning
CircuitBreakerFailureThresholdCircuitBreakerOptionsFailures required to open the circuit.
CircuitBreakerSuccessThresholdCircuitBreakerOptionsSuccessful half-open probes required to close the circuit.
CircuitBreakerRecoveryTimeoutCircuitBreakerOptionsTime before open state can move to half-open.

Advanced internal state values ​

These classes are exported because they are part of the package surface, but most applications do not need to instantiate them directly.

ClassMeaning
SemaphorePermitsCurrent available semaphore permits.
CircuitBreakerFailureCountConsecutive failure count.
CircuitBreakerSuccessCountSuccessful half-open probe count.
CircuitBreakerProbeCountActive half-open probe count.
CircuitBreakerOpenedAtTimestamp captured when a circuit breaker opens.
NextRunAtNext reserved start time for rate limiters and throttlers.
NextRunReservationReservation result containing delay and next start time.
TimerDelayBoundary object that owns conversion to Node timer APIs.

Notes ​

Migrating from Flow 2.x ​

Flow 3.x uses @haskou/value-objects 7.x. Update direct dependencies on @haskou/value-objects to a compatible 7.x version and ensure that Flow and the application resolve the same package instance. A Duration from a separate installation is not recognized by Flow's instanceof Duration input checks. Passing numeric milliseconds remains supported.

isEqual() now requires the same concrete Value Object type as well as the same value. Use hasValue() when deliberately comparing duration values across types:

typescript
const timeout = new TimeoutDuration(Duration.fromSeconds(3));

timeout.isEqual(new TimeoutDuration(Duration.fromSeconds(3))); // true
timeout.isEqual(Duration.fromSeconds(3)); // false
timeout.hasValue(Duration.fromSeconds(3)); // true
  • Prefer numbers for simple call sites: new Timeout(3000) is fine.
  • Prefer Duration when readability matters: new Timeout(Duration.fromSeconds(3)).
  • Prefer explicit configuration values when values are shared, named, or built outside the constructor call.

Released under the MIT License.