@fluidframework/core-utils Package
Interfaces
Interface | Alerts | Description |
---|---|---|
PromiseCacheOptions | Legacy |
Options for configuring the PromiseCache |
Classes
Class | Alerts | Description |
---|---|---|
Deferred | Legacy |
A deferred creates a promise and the ability to resolve or reject it |
LazyPromise | Legacy |
A lazy evaluated promise. The execute function is delayed until the promise is used, e.g. await, then, catch ... The execute function is only called once. All calls are then proxied to the promise returned by the execute method. |
PromiseCache | Legacy |
A specialized cache for async work, allowing you to safely cache the promised result of some async work without fear of running it multiple times or losing track of errors. |
Types
TypeAlias | Alerts | Description |
---|---|---|
PromiseCacheExpiry | Legacy |
Three supported expiry policies: - indefinite: entries don't expire and must be explicitly removed - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock) |
Functions
Function | Alerts | Return Type | Description |
---|---|---|---|
assert(condition, message) | Legacy |
asserts condition | Asserts the specified condition. |
compareArrays(left, right, comparator) | Legacy |
boolean | Compare two arrays. Returns true if their elements are equivalent and in the same order. |
Function Details
assert
Asserts the specified condition.
To use, import via @fluidframework/core-utils/legacy
.
For more information about our API support guarantees, see here.
Signature
export declare function assert(condition: boolean, message: string | number): asserts condition;
Remarks
Use this instead of the node 'assert' package, which requires polyfills and has a big impact on bundle sizes.
Assertions using this API will be included in all configurations: there is no option to disable or optimize them out. Thus this API is suitable for detecting conditions that should terminate the application and produce a useful diagnostic message. It can be used to ensure bad states are detected early and to avoid data corruption or harder to debug errors.
In cases where the assert is very unlikely to have an impact on production code but is still useful as documentation and for debugging, consider using debugAssert
instead to optimize bundle size.
This API is not intended for use outside of the Fluid Framework client codebase: it will most likely be made internal in the future.
Parameters
Parameter | Type | Description |
---|---|---|
condition | boolean | The condition that should be true, if the condition is false an error will be thrown. Only use this API when false indicates a logic error in the problem and thus a bug that should be fixed. |
message | string | number | The message to include in the error when the condition does not hold. A number should not be specified manually: use a string. Before a release, policy-check should be run, which will convert any asserts still using strings to use numbered error codes instead. |
Returns
Return type: asserts condition
compareArrays
Compare two arrays. Returns true if their elements are equivalent and in the same order.
To use, import via @fluidframework/core-utils/legacy
.
For more information about our API support guarantees, see here.
Signature
compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean
Type Parameters
Parameter | Description |
---|---|
T |
Parameters
Parameter | Modifiers | Type | Description |
---|---|---|---|
left | readonly T[] | The first array to compare | |
right | readonly T[] | The second array to compare | |
comparator | optional | (leftItem: T, rightItem: T, index: number) => boolean | The function used to check if two T s are equivalent. Defaults to Object.is() equality (a shallow compare where NaN = NaN and -0 ≠ 0) |
Returns
Return type: boolean