All files / src/auxiliary Convenience.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66  1x 1x 1x 1x 1x                                                       1x 1x                 1x 1x                 1x 1x                 1x 1x  
import { RequiredType } from "@jonloucks/contracts-ts/api/Types";
import { CONTRACTS } from "@jonloucks/contracts-ts";
import { CONTRACT as BOOLEAN_FACTORY } from "@jonloucks/contracts-ts/auxiliary/AtomicBooleanFactory";
import { CONTRACT as REFERENCE_FACTORY } from "@jonloucks/contracts-ts/auxiliary/AtomicReferenceFactory";
import { CONTRACT as INTEGER_FACTORY } from "@jonloucks/contracts-ts/auxiliary/AtomicIntegerFactory";
import { CONTRACT as IDEMPOTENT_FACTORY } from "@jonloucks/contracts-ts/auxiliary/IdempotentFactory";
import { AtomicBoolean } from "@jonloucks/contracts-ts/auxiliary/AtomicBoolean";
import { AtomicReference } from "@jonloucks/contracts-ts/auxiliary/AtomicReference";
import { AtomicInteger } from "@jonloucks/contracts-ts/auxiliary/AtomicInteger";
import { Idempotent, Config as IdempotentConfig } from "@jonloucks/contracts-ts/auxiliary/Idempotent";
 
export { AtomicBoolean , AtomicReference, AtomicInteger, RequiredType, Idempotent, IdempotentConfig };
 
/**
 * @module Convenience
 * @description
 * 
 * This module provides convenience functions for creating auxiliary types
 * using the shared global CONTRACTS instance. For performance-sensitive
 * applications, consider using factory instances directly to avoid the
 * overhead of enforcing the factory contract on each creation. 
 * 
 * Internal Note: To avoid circular dependencies, other modules should not
 * import from this module. Instead, they should import directly from the
 * source modules of the auxiliary types. 
 */
 
/**
 * Create an AtomicBoolean via the shared global CONTRACTS instance.
 * 
 * @param initialValue the initial boolean value
 * @returns the AtomicBoolean instance
 */
export function createAtomicBoolean(initialValue?: boolean): RequiredType<AtomicBoolean> {
  return CONTRACTS.enforce(BOOLEAN_FACTORY).createAtomicBoolean(initialValue);
}
 
/**
 * Create an AtomicReference via the shared global CONTRACTS instance.
 * 
 * @param initialValue the initial reference value
 * @returns the AtomicReference instance
 */
export function createAtomicReference<T>(initialValue?: T): RequiredType<AtomicReference<T>> {
  return CONTRACTS.enforce(REFERENCE_FACTORY).createAtomicReference(initialValue);
}
 
/**
 * Create an AtomicInteger via the shared global CONTRACTS instance.
 * 
 * @param initialValue the initial integer value
 * @returns the AtomicInteger instance
 */
export function createAtomicInteger(initialValue?: number): RequiredType<AtomicInteger> {
  return CONTRACTS.enforce(INTEGER_FACTORY).createAtomicInteger(initialValue);
}
 
/**
 * Create an Idempotent via the shared global CONTRACTS instance.
 * 
 * @param config the idempotent configuration
 * @returns the Idempotent instance
 */
export function createIdempotent(config: IdempotentConfig): RequiredType<Idempotent> {
  return CONTRACTS.enforce(IDEMPOTENT_FACTORY).createIdempotent(config);
}