@darlean/core
Version:
Darlean core functionality for creating applications that define, expose and host actors
42 lines (41 loc) • 2.1 kB
TypeScript
import { IActorLockService } from '@darlean/base';
import { ITime } from '@darlean/utils';
/**
* Allows the holder of an actor lock to release the lock.
*/
export interface IAcquiredActorLock {
/**
* Releases the lock.
*/
release(): Promise<void>;
}
/**
* Abstraction of an achtor lock that ensures only one application has
* ownership of a certain id within a certain time window.
*/
export interface IActorLock {
/**
* Acquires unique ownership of the provided id.
* @param id The id for which the current application wishes to receive unique ownership.
* @param onBroken Callback that is invoked when the lock detects that the lock
* is not valid anymore.
* @throws A {@link FrameworkError} with code {@link FRAMEWORK_ERROR_ACTOR_LOCK_FAILED} to indicate
* that the lock could not be obtained. The {@link FrameworkError} parameter {@link FRAMEWORK_ERROR_PARAMETER_REDIRECT_DESTINATION}
* should be filled with an array of application names that currently hold the lock (typically only one, but in case of
* lock conflicts multiple holders could be reported. Don't worry -- only one application will know that it actually holds the lock,
* so although multiple applications are reported by the lock, only one application will acutally hold te lock. It is just that
* the (distributed) lock does not know exactly which one). This information can be used by callers to
* determine which application is the most likely to consult next when they want to invoke actions on the actor.
*/
acquire(id: string[], onBroken: () => void): Promise<IAcquiredActorLock>;
}
/**
* Implementation of {@link IActorLock} that uses the distributed actor lock provided in {@link @darlean/actor-lock-suite}.
*/
export declare class DistributedActorLock implements IActorLock {
private service;
private time;
private appId;
constructor(time: ITime, service: IActorLockService, appId: string);
acquire(id: string[], onBroken: () => void): Promise<IAcquiredActorLock>;
}