@itwin/presentation-shared
Advanced tools
Comparing version 0.1.0 to 0.1.1
# @itwin/presentation-shared | ||
## 0.1.1 | ||
### Patch Changes | ||
- [#571](https://github.com/iTwin/presentation/pull/571): Added utility functions for releasing main thread: `releaseMainThread` and `createMainThreadReleaseOnTimePassedHandler`. | ||
## 0.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -10,5 +10,5 @@ import * as ECSql from "./shared/ecsql-snippets"; | ||
export { createCachingECClassHierarchyInspector, EC, getClass, ECClassHierarchyInspector, ECSchemaProvider } from "./shared/Metadata"; | ||
export { normalizeFullClassName, parseFullClassName, trimWhitespace } from "./shared/Utils"; | ||
export { normalizeFullClassName, parseFullClassName, trimWhitespace, releaseMainThread, createMainThreadReleaseOnTimePassedHandler } from "./shared/Utils"; | ||
export { InstanceKey, PrimitiveValue, TypedPrimitiveValue } from "./shared/Values"; | ||
export { Event } from "./shared/Event"; | ||
//# sourceMappingURL=presentation-shared.d.ts.map |
@@ -30,3 +30,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TypedPrimitiveValue = exports.PrimitiveValue = exports.InstanceKey = exports.trimWhitespace = exports.parseFullClassName = exports.normalizeFullClassName = exports.getClass = exports.createCachingECClassHierarchyInspector = exports.NOOP_LOGGER = exports.parseInstanceLabel = exports.createBisInstanceLabelSelectClauseFactory = exports.createClassBasedInstanceLabelSelectClauseFactory = exports.createDefaultInstanceLabelSelectClauseFactory = exports.formatConcatenatedValue = exports.createDefaultValueFormatter = exports.ConcatenatedValuePart = exports.ConcatenatedValue = exports.ECSql = void 0; | ||
exports.TypedPrimitiveValue = exports.PrimitiveValue = exports.InstanceKey = exports.createMainThreadReleaseOnTimePassedHandler = exports.releaseMainThread = exports.trimWhitespace = exports.parseFullClassName = exports.normalizeFullClassName = exports.getClass = exports.createCachingECClassHierarchyInspector = exports.NOOP_LOGGER = exports.parseInstanceLabel = exports.createBisInstanceLabelSelectClauseFactory = exports.createClassBasedInstanceLabelSelectClauseFactory = exports.createDefaultInstanceLabelSelectClauseFactory = exports.formatConcatenatedValue = exports.createDefaultValueFormatter = exports.ConcatenatedValuePart = exports.ConcatenatedValue = exports.ECSql = void 0; | ||
// eslint-disable-next-line @itwin/no-internal-barrel-imports | ||
@@ -55,2 +55,4 @@ const ECSql = __importStar(require("./shared/ecsql-snippets")); | ||
Object.defineProperty(exports, "trimWhitespace", { enumerable: true, get: function () { return Utils_1.trimWhitespace; } }); | ||
Object.defineProperty(exports, "releaseMainThread", { enumerable: true, get: function () { return Utils_1.releaseMainThread; } }); | ||
Object.defineProperty(exports, "createMainThreadReleaseOnTimePassedHandler", { enumerable: true, get: function () { return Utils_1.createMainThreadReleaseOnTimePassedHandler; } }); | ||
var Values_1 = require("./shared/Values"); | ||
@@ -57,0 +59,0 @@ Object.defineProperty(exports, "InstanceKey", { enumerable: true, get: function () { return Values_1.InstanceKey; } }); |
@@ -26,2 +26,26 @@ /** | ||
export declare function trimWhitespace(str: string | undefined): string | undefined; | ||
/** | ||
* An utility that returns a promise that immediately resolves. Awaiting on the returned | ||
* promise releases the main thread and allows other tasks to run. | ||
* | ||
* @beta | ||
*/ | ||
export declare function releaseMainThread(): Promise<void>; | ||
/** | ||
* An utility that returns a `releaseMainThread` promise if the given amount of time has passed since the handler | ||
* was created or the main thread was last released using this handler. Otherwise, returns `undefined`. | ||
* | ||
* Example: | ||
* ```ts | ||
* const releaseMainThread = createMainThreadReleaseOnTimePassedHandler(); | ||
* for (const value of someVeryLargeArray) { | ||
* await releaseMainThread(); | ||
* // do something with value | ||
* } | ||
* ``` | ||
* | ||
* @param releaseOnTimePassed The amount of time in milliseconds after which the main thread should be released. Defaults to `40` ms. | ||
* @beta | ||
*/ | ||
export declare function createMainThreadReleaseOnTimePassedHandler(releaseOnTimePassed?: number): () => Promise<void> | undefined; | ||
//# sourceMappingURL=Utils.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.trimWhitespace = exports.normalizeFullClassName = exports.parseFullClassName = void 0; | ||
exports.createMainThreadReleaseOnTimePassedHandler = exports.releaseMainThread = exports.trimWhitespace = exports.normalizeFullClassName = exports.parseFullClassName = void 0; | ||
const core_bentley_1 = require("@itwin/core-bentley"); | ||
@@ -51,2 +51,41 @@ /** | ||
exports.trimWhitespace = trimWhitespace; | ||
/** | ||
* An utility that returns a promise that immediately resolves. Awaiting on the returned | ||
* promise releases the main thread and allows other tasks to run. | ||
* | ||
* @beta | ||
*/ | ||
async function releaseMainThread() { | ||
return new Promise((resolve) => setTimeout(resolve, 0)); | ||
} | ||
exports.releaseMainThread = releaseMainThread; | ||
/** | ||
* An utility that returns a `releaseMainThread` promise if the given amount of time has passed since the handler | ||
* was created or the main thread was last released using this handler. Otherwise, returns `undefined`. | ||
* | ||
* Example: | ||
* ```ts | ||
* const releaseMainThread = createMainThreadReleaseOnTimePassedHandler(); | ||
* for (const value of someVeryLargeArray) { | ||
* await releaseMainThread(); | ||
* // do something with value | ||
* } | ||
* ``` | ||
* | ||
* @param releaseOnTimePassed The amount of time in milliseconds after which the main thread should be released. Defaults to `40` ms. | ||
* @beta | ||
*/ | ||
function createMainThreadReleaseOnTimePassedHandler(releaseOnTimePassed = 40) { | ||
let start = Date.now(); | ||
return () => { | ||
const elapsed = Date.now() - start; | ||
if (elapsed < releaseOnTimePassed) { | ||
return undefined; | ||
} | ||
return releaseMainThread().then(() => { | ||
start = Date.now(); | ||
}); | ||
}; | ||
} | ||
exports.createMainThreadReleaseOnTimePassedHandler = createMainThreadReleaseOnTimePassedHandler; | ||
//# sourceMappingURL=Utils.js.map |
@@ -10,5 +10,5 @@ import * as ECSql from "./shared/ecsql-snippets"; | ||
export { createCachingECClassHierarchyInspector, EC, getClass, ECClassHierarchyInspector, ECSchemaProvider } from "./shared/Metadata"; | ||
export { normalizeFullClassName, parseFullClassName, trimWhitespace } from "./shared/Utils"; | ||
export { normalizeFullClassName, parseFullClassName, trimWhitespace, releaseMainThread, createMainThreadReleaseOnTimePassedHandler } from "./shared/Utils"; | ||
export { InstanceKey, PrimitiveValue, TypedPrimitiveValue } from "./shared/Values"; | ||
export { Event } from "./shared/Event"; | ||
//# sourceMappingURL=presentation-shared.d.ts.map |
@@ -13,4 +13,4 @@ /*--------------------------------------------------------------------------------------------- | ||
export { createCachingECClassHierarchyInspector, getClass } from "./shared/Metadata"; | ||
export { normalizeFullClassName, parseFullClassName, trimWhitespace } from "./shared/Utils"; | ||
export { normalizeFullClassName, parseFullClassName, trimWhitespace, releaseMainThread, createMainThreadReleaseOnTimePassedHandler } from "./shared/Utils"; | ||
export { InstanceKey, PrimitiveValue, TypedPrimitiveValue } from "./shared/Values"; | ||
//# sourceMappingURL=presentation-shared.js.map |
@@ -26,2 +26,26 @@ /** | ||
export declare function trimWhitespace(str: string | undefined): string | undefined; | ||
/** | ||
* An utility that returns a promise that immediately resolves. Awaiting on the returned | ||
* promise releases the main thread and allows other tasks to run. | ||
* | ||
* @beta | ||
*/ | ||
export declare function releaseMainThread(): Promise<void>; | ||
/** | ||
* An utility that returns a `releaseMainThread` promise if the given amount of time has passed since the handler | ||
* was created or the main thread was last released using this handler. Otherwise, returns `undefined`. | ||
* | ||
* Example: | ||
* ```ts | ||
* const releaseMainThread = createMainThreadReleaseOnTimePassedHandler(); | ||
* for (const value of someVeryLargeArray) { | ||
* await releaseMainThread(); | ||
* // do something with value | ||
* } | ||
* ``` | ||
* | ||
* @param releaseOnTimePassed The amount of time in milliseconds after which the main thread should be released. Defaults to `40` ms. | ||
* @beta | ||
*/ | ||
export declare function createMainThreadReleaseOnTimePassedHandler(releaseOnTimePassed?: number): () => Promise<void> | undefined; | ||
//# sourceMappingURL=Utils.d.ts.map |
@@ -44,2 +44,39 @@ /*--------------------------------------------------------------------------------------------- | ||
} | ||
/** | ||
* An utility that returns a promise that immediately resolves. Awaiting on the returned | ||
* promise releases the main thread and allows other tasks to run. | ||
* | ||
* @beta | ||
*/ | ||
export async function releaseMainThread() { | ||
return new Promise((resolve) => setTimeout(resolve, 0)); | ||
} | ||
/** | ||
* An utility that returns a `releaseMainThread` promise if the given amount of time has passed since the handler | ||
* was created or the main thread was last released using this handler. Otherwise, returns `undefined`. | ||
* | ||
* Example: | ||
* ```ts | ||
* const releaseMainThread = createMainThreadReleaseOnTimePassedHandler(); | ||
* for (const value of someVeryLargeArray) { | ||
* await releaseMainThread(); | ||
* // do something with value | ||
* } | ||
* ``` | ||
* | ||
* @param releaseOnTimePassed The amount of time in milliseconds after which the main thread should be released. Defaults to `40` ms. | ||
* @beta | ||
*/ | ||
export function createMainThreadReleaseOnTimePassedHandler(releaseOnTimePassed = 40) { | ||
let start = Date.now(); | ||
return () => { | ||
const elapsed = Date.now() - start; | ||
if (elapsed < releaseOnTimePassed) { | ||
return undefined; | ||
} | ||
return releaseMainThread().then(() => { | ||
start = Date.now(); | ||
}); | ||
}; | ||
} | ||
//# sourceMappingURL=Utils.js.map |
{ | ||
"name": "@itwin/presentation-shared", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "The package contains types and utilities used across different iTwin.js Presentation packages.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -435,1 +435,13 @@ # @itwin/presentation-shared | ||
- spaces at the beginning and end of the string. | ||
- `releaseMainThread` - returns a promise that immediately resolves. Awaiting on the returned promise releases the main thread and allows other tasks to run. | ||
- `createMainThreadReleaseOnTimePassedHandler` - returns a `releaseMainThread` promise if the given amount of time has passed since the handler was created or the main thread was last released using this handler. Otherwise, returns `undefined`. | ||
```ts | ||
const releaseMainThread = createMainThreadReleaseOnTimePassedHandler(); | ||
for (const value of someVeryLargeArray) { | ||
await releaseMainThread(); | ||
// do something with value | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
287434
4096
447