當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。