mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Fix more azurecore strict nulls (#20547)
This commit is contained in:
@@ -15,11 +15,11 @@ export class AlreadyInitializedError extends Error {
|
||||
}
|
||||
|
||||
export class FileDatabase {
|
||||
private db: { [key: string]: string };
|
||||
private db: { [key: string]: string } = {};
|
||||
private isDirty = false;
|
||||
private isSaving = false;
|
||||
private isInitialized = false;
|
||||
private saveInterval: NodeJS.Timer;
|
||||
private saveInterval: NodeJS.Timer | undefined;
|
||||
|
||||
constructor(
|
||||
private readonly dbPath: string,
|
||||
@@ -91,7 +91,7 @@ export class FileDatabase {
|
||||
|
||||
public async initialize(): Promise<void> {
|
||||
this.isInitialized = true;
|
||||
this.setupSaveTask();
|
||||
this.saveInterval = setInterval(() => this.save(), 20 * 1000);
|
||||
let fileContents: string;
|
||||
try {
|
||||
await fs.access(this.dbPath, fsConstants.R_OK | fsConstants.R_OK);
|
||||
@@ -114,13 +114,11 @@ export class FileDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
private setupSaveTask(): NodeJS.Timer {
|
||||
return setInterval(() => this.save(), 20 * 1000);
|
||||
}
|
||||
|
||||
public async shutdown(): Promise<void> {
|
||||
await this.waitForFileSave();
|
||||
clearInterval((this.saveInterval));
|
||||
if (this.saveInterval) {
|
||||
clearInterval(this.saveInterval);
|
||||
}
|
||||
await this.save();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,21 +11,27 @@ export type WebHandler = (req: http.IncomingMessage, reqUrl: url.UrlWithParsedQu
|
||||
export class AlreadyRunningError extends Error { }
|
||||
|
||||
export class SimpleWebServer {
|
||||
private hasStarted: boolean;
|
||||
private hasStarted: boolean = false;
|
||||
|
||||
private readonly pathMappings = new Map<string, WebHandler>();
|
||||
private readonly server: http.Server;
|
||||
private lastUsed: number;
|
||||
private lastUsed: number = new Date().getTime();
|
||||
private shutoffInterval: NodeJS.Timer;
|
||||
|
||||
constructor(private readonly autoShutoffTimer = 5 * 60 * 1000) { // Default to five minutes.
|
||||
this.bumpLastUsed();
|
||||
this.autoShutoff();
|
||||
this.shutoffInterval = setInterval(() => {
|
||||
const time = new Date().getTime();
|
||||
|
||||
if (time - this.lastUsed > this.autoShutoffTimer) {
|
||||
console.log('Shutting off webserver...');
|
||||
this.shutdown().catch(console.error);
|
||||
}
|
||||
}, 1000);
|
||||
this.server = http.createServer((req, res) => {
|
||||
this.bumpLastUsed();
|
||||
const reqUrl = url.parse(req.url!, /* parseQueryString */ true);
|
||||
|
||||
const handler = this.pathMappings.get(reqUrl.pathname);
|
||||
const handler = reqUrl.pathname ? this.pathMappings.get(reqUrl.pathname) : undefined;
|
||||
if (handler) {
|
||||
return handler(req, reqUrl, res);
|
||||
}
|
||||
@@ -95,15 +101,4 @@ export class SimpleWebServer {
|
||||
public on(pathMapping: string, handler: WebHandler) {
|
||||
this.pathMappings.set(pathMapping, handler);
|
||||
}
|
||||
|
||||
private autoShutoff(): void {
|
||||
this.shutoffInterval = setInterval(() => {
|
||||
const time = new Date().getTime();
|
||||
|
||||
if (time - this.lastUsed > this.autoShutoffTimer) {
|
||||
console.log('Shutting off webserver...');
|
||||
this.shutdown().catch(console.error);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user