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 | 25x 13x 14x 13x 11x 13x 13x 13x | import { Promisor } from "@jonloucks/contracts-ts/api/Promisor";
import { OptionalType, RequiredType } from "@jonloucks/contracts-ts/api/Types";
/**
* Factory method to create an constant value promisor implementation
*
* @param referent the source promisor
* @param <T> the type of deliverable
* @returns the new constant value Promisor implementation
*/
export function create<T>(value: OptionalType<T>): RequiredType<Promisor<T>> {
return ValuePromisorImpl.internalCreate(value);
}
// ---- Implementation details below ----
/**
* Implementation of a constant value Promisor
* @param <T> The type of deliverable
*/
class ValuePromisorImpl<T> implements Promisor<T> {
demand(): OptionalType<T> {
return this.value
}
incrementUsage(): number {
return 1;
}
decrementUsage(): number {
return 1;
}
static internalCreate<T>(value: OptionalType<T>): RequiredType<Promisor<T>> {
return new ValuePromisorImpl<T>(value);
}
private constructor(value: OptionalType<T>) {
this.value = value;
Object.freeze(this.value);
}
private readonly value: OptionalType<T>;
}
|