当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript event.Event类代码示例

本文整理汇总了TypeScript中vs/base/common/event.Event的典型用法代码示例。如果您正苦于以下问题:TypeScript Event类的具体用法?TypeScript Event怎么用?TypeScript Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Event类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getOnDidClientConnect

	private static getOnDidClientConnect(): Event<ClientConnectionEvent> {
		const onHello = Event.fromNodeEventEmitter<Electron.WebContents>(ipcMain, 'ipc:hello', ({ sender }) => sender);

		return Event.map(onHello, webContents => {
			const onMessage = createScopedOnMessageEvent(webContents.id, 'ipc:message');
			const onDidClientDisconnect = Event.signal(createScopedOnMessageEvent(webContents.id, 'ipc:disconnect'));
			const protocol = new Protocol(webContents, onMessage);

			return { protocol, onDidClientDisconnect };
		});
	}
开发者ID:VishalMadhvani,项目名称:vscode,代码行数:11,代码来源:ipc.electron-main.ts

示例2: extractEntry

function extractEntry(stream: Readable, fileName: string, mode: number, targetPath: string, options: IOptions, token: CancellationToken): Promise<void> {
	const dirName = path.dirname(fileName);
	const targetDirName = path.join(targetPath, dirName);
	if (targetDirName.indexOf(targetPath) !== 0) {
		return Promise.reject(new Error(nls.localize('invalid file', "Error extracting {0}. Invalid file.", fileName)));
	}
	const targetFileName = path.join(targetPath, fileName);

	let istream: WriteStream;

	Event.once(token.onCancellationRequested)(() => {
		if (istream) {
			istream.destroy();
		}
	});

	return Promise.resolve(mkdirp(targetDirName, undefined, token)).then(() => new Promise<void>((c, e) => {
		if (token.isCancellationRequested) {
			return;
		}

		try {
			istream = createWriteStream(targetFileName, { mode });
			istream.once('close', () => c());
			istream.once('error', e);
			stream.once('error', e);
			stream.pipe(istream);
		} catch (error) {
			e(error);
		}
	}));
}
开发者ID:joelday,项目名称:vscode,代码行数:32,代码来源:zip.ts

示例3: flush

export function echo<T>(event: Event<T>, nextTick = false, buffer: T[] = []): { clear: () => void; event: Event<T> } {
	buffer = buffer.slice();

	event(e => {
		buffer.push(e);
		emitter.fire(e);
	});

	const flush = (listener: (e: T) => any, thisArgs?: any) => buffer.forEach(e => listener.call(thisArgs, e));
	const clear = () => buffer = [];

	const emitter = new Emitter<T>({
		onListenerDidAdd(emitter, listener: (e: T) => any, thisArgs?: any) {
			if (nextTick) {
				setTimeout(() => flush(listener, thisArgs));
			} else {
				flush(listener, thisArgs);
			}
		}
	});

	return {
		event: emitter.event,
		clear
	};
}
开发者ID:burhandodhy,项目名称:azuredatastudio,代码行数:26,代码来源:event.ts

示例4: listen

	listen(_, event: string, arg?: any): Event<any> {
		switch (event) {
			case 'upload': return Event.buffer(upload(URI.revive(arg)));
		}

		throw new Error(`Event not found: ${event}`);
	}
开发者ID:donaldpipowitch,项目名称:vscode,代码行数:7,代码来源:downloadIpc.ts

示例5:

export function stop<T extends CancellableEvent>(event: BaseEvent<T>): BaseEvent<T> {
	return BaseEvent.map(event, e => {
		e.preventDefault();
		e.stopPropagation();
		return e;
	});
}
开发者ID:PKRoma,项目名称:vscode,代码行数:7,代码来源:event.ts

示例6:

		(import('windows-process-tree')).then(mod => {
			if (this._isDisposed) {
				return;
			}

			windowsProcessTree = mod;
			this._onCheckShell = new Emitter<Promise<string>>();
			// The debounce is necessary to prevent multiple processes from spawning when
			// the enter key or output is spammed
			Event.debounce(this._onCheckShell.event, (l, e) => e, 150, true)(() => {
				setTimeout(() => {
					this.checkShell();
				}, 50);
			});

			// We want to fire a new check for the shell on a linefeed, but only
			// when parsing has finished which is indicated by the cursormove event.
			// If this is done on every linefeed, parsing ends up taking
			// significantly longer due to resetting timers. Note that this is
			// private API.
			this._xterm.on('linefeed', () => this._newLineFeed = true);
			this._xterm.on('cursormove', () => {
				if (this._newLineFeed) {
					this._onCheckShell.fire(undefined);
				}
			});

			// Fire a new check for the shell when any key is pressed.
			this._xterm.on('keypress', () => this._onCheckShell.fire(undefined));
		});
开发者ID:eamodio,项目名称:vscode,代码行数:30,代码来源:windowsShellHelper.ts

示例7: createScopedOnMessageEvent

		return Event.map(onHello, webContents => {
			const onMessage = createScopedOnMessageEvent(webContents.id, 'ipc:message');
			const onDidClientDisconnect = Event.signal(createScopedOnMessageEvent(webContents.id, 'ipc:disconnect'));
			const protocol = new Protocol(webContents, onMessage);

			return { protocol, onDidClientDisconnect };
		});
开发者ID:VishalMadhvani,项目名称:vscode,代码行数:7,代码来源:ipc.electron-main.ts

示例8: extractZip

function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, logService: ILogService, token: CancellationToken): Promise<void> {
	let last = createCancelablePromise<void>(() => Promise.resolve());
	let extractedEntriesCount = 0;

	Event.once(token.onCancellationRequested)(() => {
		logService.debug(targetPath, 'Cancelled.');
		last.cancel();
		zipfile.close();
	});

	return new Promise((c, e) => {
		const throttler = new Sequencer();

		const readNextEntry = (token: CancellationToken) => {
			if (token.isCancellationRequested) {
				return;
			}

			extractedEntriesCount++;
			zipfile.readEntry();
		};

		zipfile.once('error', e);
		zipfile.once('close', () => last.then(() => {
			if (token.isCancellationRequested || zipfile.entryCount === extractedEntriesCount) {
				c();
			} else {
				e(new ExtractError('Incomplete', new Error(nls.localize('incompleteExtract', "Incomplete. Found {0} of {1} entries", extractedEntriesCount, zipfile.entryCount))));
			}
		}, e));
		zipfile.readEntry();
		zipfile.on('entry', (entry: Entry) => {

			if (token.isCancellationRequested) {
				return;
			}

			if (!options.sourcePathRegex.test(entry.fileName)) {
				readNextEntry(token);
				return;
			}

			const fileName = entry.fileName.replace(options.sourcePathRegex, '');

			// directory file names end with '/'
			if (/\/$/.test(fileName)) {
				const targetFileName = path.join(targetPath, fileName);
				last = createCancelablePromise(token => mkdirp(targetFileName, void 0, token).then(() => readNextEntry(token)).then(void 0, e));
				return;
			}

			const stream = ninvoke(zipfile, zipfile.openReadStream, entry);
			const mode = modeFromEntry(entry);

			last = createCancelablePromise(token => throttler.queue(() => stream.then(stream => extractEntry(stream, fileName, mode, targetPath, options, token).then(() => readNextEntry(token)))).then(null!, e));
		});
	});
}
开发者ID:donaldpipowitch,项目名称:vscode,代码行数:58,代码来源:zip.ts

示例9: listen

	listen(context, event: string): Event<any> {
		const uriTransformer = this.getUriTransformer(context);
		switch (event) {
			case 'onInstallExtension': return this.onInstallExtension;
			case 'onDidInstallExtension': return Event.map(this.onDidInstallExtension, i => ({ ...i, local: this._transformOutgoing(i.local, uriTransformer) }));
			case 'onUninstallExtension': return this.onUninstallExtension;
			case 'onDidUninstallExtension': return this.onDidUninstallExtension;
		}

		throw new Error('Invalid listen');
	}
开发者ID:donaldpipowitch,项目名称:vscode,代码行数:11,代码来源:extensionManagementIpc.ts

示例10: test

	test('vscode.languages.onDidChangeDiagnostics Does Not Provide Document URI #49582', async function () {
		let emitter = new Emitter<Array<string | URI>>();
		let collection = new DiagnosticCollection('ddd', 'test', 100, new DiagnosticsShape(), emitter);

		let diag1 = new Diagnostic(new Range(1, 1, 2, 3), 'diag1');

		// delete
		collection.set(URI.parse('aa:bb'), [diag1]);
		let p = Event.toPromise(emitter.event).then(e => {
			assert.equal(e[0].toString(), 'aa:bb');
		});
		collection.delete(URI.parse('aa:bb'));
		await p;

		// set->undefined (as delete)
		collection.set(URI.parse('aa:bb'), [diag1]);
		p = Event.toPromise(emitter.event).then(e => {
			assert.equal(e[0].toString(), 'aa:bb');
		});
		collection.set(URI.parse('aa:bb'), undefined!);
		await p;
	});
开发者ID:VishalMadhvani,项目名称:vscode,代码行数:22,代码来源:extHostDiagnostics.test.ts


注:本文中的vs/base/common/event.Event类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。