From 3ab32ad5f0b0fbeb67868c146fd4e3d3b6575b4c Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Tue, 5 Jun 2018 19:51:42 +0200 Subject: [PATCH] Use .once instead of .on for only-happens-once events (stop possible memory leaks) --- src/manager.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/manager.ts b/src/manager.ts index 36584d8..b6e6d3d 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -285,24 +285,24 @@ export class Manager implements vscode.FileSystemProvider, vscode.TreeDataProvid if (config == null) return reject(null); const sock = await this.createSocket(config); const client = new Client(); - client.on('ready', () => { + client.once('ready', () => { client.sftp((err, sftp) => { if (err) { client.end(); return reject(err); } - sftp.on('end', () => client.end()); + sftp.once('end', () => client.end()); const fs = new SSHFileSystem(name, sftp, config!.root || '/', config!); this.fileSystems.push(fs); delete this.creatingFileSystems[name]; vscode.commands.executeCommand('workbench.files.action.refreshFilesExplorer'); this.onDidChangeTreeDataEmitter.fire(); - client.on('close', hadError => hadError ? this.commandReconnect(name) : (!fs.closing && this.promptReconnect(name))); + client.once('close', hadError => hadError ? this.commandReconnect(name) : (!fs.closing && this.promptReconnect(name))); return resolve(fs); }); }); - client.on('timeout', () => reject(new Error(`Socket timed out while connecting SSH FS '${name}'`))); - client.on('error', (error) => { + client.once('timeout', () => reject(new Error(`Socket timed out while connecting SSH FS '${name}'`))); + client.once('error', (error) => { if (error.description) { error.message = `${error.description}\n${error.message}`; }