@senspark/sfs2x
Version:
utility library for smartfox server
39 lines (32 loc) • 1 kB
text/typescript
import { Connection } from "./Connection";
export class GuardedConnection implements Connection {
private isLoggingIn: boolean = false;
private isLoggingOut: boolean = false;
public constructor(private readonly connection: Connection) {
}
public get userId(): string {
return this.connection.userId;
}
public get isLoggedIn(): boolean {
return this.connection.isLoggedIn;
}
public async logIn(): Promise<void> {
if (this.isLoggingIn) {
throw new Error('Already logging in');
}
this.isLoggingIn = true;
await this.connection.logIn();
this.isLoggingIn = false;
}
public async logOut(): Promise<void> {
if (this.isLoggingOut) {
throw new Error('Already logging out');
}
this.isLoggingOut = true;
await this.connection.logOut();
this.isLoggingOut = false;
}
public destroy(): void {
this.connection.destroy();
}
}