raspi-io-server-utils
Version:
Utilities for interacting with Raspberry IOs and Raspbian
54 lines (53 loc) • 1.65 kB
TypeScript
declare const EventEmitter: any;
/**
* Simple implementation of a vector clock.
*
* Events:
* - `new-time` when the time of any member changed
* - `time` when the time of the owner was changed by a client (may be renamed in future)
*/
export declare class VectorClock extends EventEmitter {
private readonly _ownId;
private _clock;
constructor(data: {
owner: string;
time?: any[];
});
readonly id: string;
time: number;
readonly timestamps: {
id: string;
time: number;
}[];
readonly json: {
owner: string;
time: {
id: string;
time: number;
}[];
};
nextTick(): this;
newerThan(other: VectorClock): boolean;
/**
* @param otherClock
* @returns true, if this clock holds information about the owner of another clock.
*/
knowsOwnerOf(otherClock: VectorClock): boolean;
/**
* Only checks the timestamp of this clock's owner, ignores all other timestamps
*/
ownTimestampNewerThan(other: VectorClock): boolean;
/**
* Integrate vector time of other into own time (update timestamps of all clients)
* @param other
* @param canUpdateMyTime Set to true if other clocks can update the time of this clock.
* This is useful e.g. if the owner of this clock could go offline and lose the current time, so it is recovered.
*/
syncFrom(other: VectorClock, canUpdateMyTime?: boolean): this;
timeOf(id: string): number;
toString(): string;
updateOther(id: string, time: number): boolean;
_ownClockUpdated(): void;
_newTime(): void;
}
export {};