@itwin/core-frontend
Version:
iTwin.js frontend components
38 lines • 1.38 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module IModelConnection
*/
import { BentleyStatus } from "@itwin/core-bentley";
import { IModelError, RpcRoutingToken } from "@itwin/core-common";
/**
* Controls the RPC routing for an iModel connection.
* @public
*/
export class IModelRoutingContext {
static _current;
static for(token) {
return new IModelRoutingContext(token);
}
static default = new IModelRoutingContext(RpcRoutingToken.default);
static get current() {
return this._current;
}
token;
get active() { return IModelRoutingContext.current === this; }
constructor(token) {
this.token = token;
}
route(handler) {
if (IModelRoutingContext.current) {
throw new IModelError(BentleyStatus.ERROR, "Concurrent use is not supported.");
}
IModelRoutingContext._current = this;
const value = handler();
IModelRoutingContext._current = undefined;
return value;
}
}
//# sourceMappingURL=IModelRoutingContext.js.map