• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lifecycle.toDisposable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: registerWindowDriver

export async function registerWindowDriver(
	client: IPCClient,
	windowId: number,
	instantiationService: IInstantiationService
): TPromise<IDisposable> {
	const windowDriver = instantiationService.createInstance(WindowDriver);
	const windowDriverChannel = new WindowDriverChannel(windowDriver);
	client.registerChannel('windowDriver', windowDriverChannel);

	const windowDriverRegistryChannel = client.getChannel('windowDriverRegistry');
	const windowDriverRegistry = new WindowDriverRegistryChannelClient(windowDriverRegistryChannel);

	await windowDriverRegistry.registerWindowDriver(windowId);

	const disposable = toDisposable(() => windowDriverRegistry.reloadWindowDriver(windowId));
	return combinedDisposable([disposable, client]);
}
开发者ID:jumpinjackie,项目名称:sqlopsstudio,代码行数:17,代码来源:driver.ts


示例2: installErrorListeners

	protected installErrorListeners(): void {
		let oldOnError: Function;
		let that = this;
		if (typeof globals.onerror === 'function') {
			oldOnError = globals.onerror;
		}
		globals.onerror = function (message: string, filename: string, line: number, column?: number, e?: any) {
			that._onUncaughtError(message, filename, line, column, e);
			if (oldOnError) {
				oldOnError.apply(this, arguments);
			}
		};
		this._disposables.push(toDisposable(function () {
			if (oldOnError) {
				globals.onerror = oldOnError;
			}
		}));
	}
开发者ID:PKRoma,项目名称:vscode,代码行数:18,代码来源:errorTelemetry.ts


示例3: NullFileSystemProvider

		service.registerProvider('test', new NullFileSystemProvider(() => {
			return toDisposable(() => {
				disposeCounter++;
			});
		}));
开发者ID:PKRoma,项目名称:vscode,代码行数:5,代码来源:fileService.test.ts


示例4: normalizeNFC

		watcher.on('change', (type, raw) => {
			if (disposed) {
				return; // ignore if already disposed
			}

			// Normalize file name
			let changedFileName: string = '';
			if (raw) { // https://github.com/Microsoft/vscode/issues/38191
				changedFileName = raw.toString();
				if (isMacintosh) {
					// Mac: uses NFD unicode form on disk, but we want NFC
					// See also https://github.com/nodejs/node/issues/2165
					changedFileName = normalizeNFC(changedFileName);
				}
			}

			if (!changedFileName || (type !== 'change' && type !== 'rename')) {
				return; // ignore unexpected events
			}

			// File path: use path directly for files and join with changed file name otherwise
			const changedFilePath = file.isDirectory ? join(file.path, changedFileName) : file.path;

			// File
			if (!file.isDirectory) {
				if (type === 'rename' || changedFileName !== originalFileName) {
					// The file was either deleted or renamed. Many tools apply changes to files in an
					// atomic way ("Atomic Save") by first renaming the file to a temporary name and then
					// renaming it back to the original name. Our watcher will detect this as a rename
					// and then stops to work on Mac and Linux because the watcher is applied to the
					// inode and not the name. The fix is to detect this case and trying to watch the file
					// again after a certain delay.
					// In addition, we send out a delete event if after a timeout we detect that the file
					// does indeed not exist anymore.

					const timeoutHandle = setTimeout(async () => {
						const fileExists = await exists(changedFilePath);

						if (disposed) {
							return; // ignore if disposed by now
						}

						// File still exists, so emit as change event and reapply the watcher
						if (fileExists) {
							onChange('changed', changedFilePath);

							watcherDisposables = [doWatchNonRecursive(file, onChange, onError)];
						}

						// File seems to be really gone, so emit a deleted event
						else {
							onChange('deleted', changedFilePath);
						}
					}, CHANGE_BUFFER_DELAY);

					// Very important to dispose the watcher which now points to a stale inode
					// and wire in a new disposable that tracks our timeout that is installed
					dispose(watcherDisposables);
					watcherDisposables = [toDisposable(() => clearTimeout(timeoutHandle))];
				} else {
					onChange('changed', changedFilePath);
				}
			}

			// Folder
			else {

				// Children add/delete
				if (type === 'rename') {

					// Cancel any previous stats for this file path if existing
					const statDisposable = mapPathToStatDisposable.get(changedFilePath);
					if (statDisposable) {
						dispose(statDisposable);
					}

					// Wait a bit and try see if the file still exists on disk to decide on the resulting event
					const timeoutHandle = setTimeout(async () => {
						mapPathToStatDisposable.delete(changedFilePath);

						const fileExists = await exists(changedFilePath);

						if (disposed) {
							return; // ignore if disposed by now
						}

						// Figure out the correct event type:
						// File Exists: either 'added' or 'changed' if known before
						// File Does not Exist: always 'deleted'
						let type: 'added' | 'deleted' | 'changed';
						if (fileExists) {
							if (folderChildren.has(changedFileName)) {
								type = 'changed';
							} else {
								type = 'added';
								folderChildren.add(changedFileName);
							}
						} else {
							folderChildren.delete(changedFileName);
							type = 'deleted';
//.........这里部分代码省略.........
开发者ID:PKRoma,项目名称:vscode,代码行数:101,代码来源:watcher.ts


示例5: doWatchNonRecursive

function doWatchNonRecursive(file: { path: string, isDirectory: boolean }, onChange: (type: 'added' | 'changed' | 'deleted', path: string) => void, onError: (error: string) => void): IDisposable {
	const originalFileName = basename(file.path);
	const mapPathToStatDisposable = new Map<string, IDisposable>();

	let disposed = false;
	let watcherDisposables: IDisposable[] = [toDisposable(() => {
		mapPathToStatDisposable.forEach(disposable => dispose(disposable));
		mapPathToStatDisposable.clear();
	})];

	try {

		// Creating watcher can fail with an exception
		const watcher = watch(file.path);
		watcherDisposables.push(toDisposable(() => {
			watcher.removeAllListeners();
			watcher.close();
		}));

		// Folder: resolve children to emit proper events
		const folderChildren: Set<string> = new Set<string>();
		if (file.isDirectory) {
			readdir(file.path).then(children => children.forEach(child => folderChildren.add(child)));
		}

		watcher.on('error', (code: number, signal: string) => {
			if (!disposed) {
				onError(`Failed to watch ${file.path} for changes using fs.watch() (${code}, ${signal})`);
			}
		});

		watcher.on('change', (type, raw) => {
			if (disposed) {
				return; // ignore if already disposed
			}

			// Normalize file name
			let changedFileName: string = '';
			if (raw) { // https://github.com/Microsoft/vscode/issues/38191
				changedFileName = raw.toString();
				if (isMacintosh) {
					// Mac: uses NFD unicode form on disk, but we want NFC
					// See also https://github.com/nodejs/node/issues/2165
					changedFileName = normalizeNFC(changedFileName);
				}
			}

			if (!changedFileName || (type !== 'change' && type !== 'rename')) {
				return; // ignore unexpected events
			}

			// File path: use path directly for files and join with changed file name otherwise
			const changedFilePath = file.isDirectory ? join(file.path, changedFileName) : file.path;

			// File
			if (!file.isDirectory) {
				if (type === 'rename' || changedFileName !== originalFileName) {
					// The file was either deleted or renamed. Many tools apply changes to files in an
					// atomic way ("Atomic Save") by first renaming the file to a temporary name and then
					// renaming it back to the original name. Our watcher will detect this as a rename
					// and then stops to work on Mac and Linux because the watcher is applied to the
					// inode and not the name. The fix is to detect this case and trying to watch the file
					// again after a certain delay.
					// In addition, we send out a delete event if after a timeout we detect that the file
					// does indeed not exist anymore.

					const timeoutHandle = setTimeout(async () => {
						const fileExists = await exists(changedFilePath);

						if (disposed) {
							return; // ignore if disposed by now
						}

						// File still exists, so emit as change event and reapply the watcher
						if (fileExists) {
							onChange('changed', changedFilePath);

							watcherDisposables = [doWatchNonRecursive(file, onChange, onError)];
						}

						// File seems to be really gone, so emit a deleted event
						else {
							onChange('deleted', changedFilePath);
						}
					}, CHANGE_BUFFER_DELAY);

					// Very important to dispose the watcher which now points to a stale inode
					// and wire in a new disposable that tracks our timeout that is installed
					dispose(watcherDisposables);
					watcherDisposables = [toDisposable(() => clearTimeout(timeoutHandle))];
				} else {
					onChange('changed', changedFilePath);
				}
			}

			// Folder
			else {

				// Children add/delete
				if (type === 'rename') {
//.........这里部分代码省略.........
开发者ID:PKRoma,项目名称:vscode,代码行数:101,代码来源:watcher.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lifecycle.IDisposable类代码示例发布时间:2022-05-25
下一篇:
TypeScript lifecycle.disposeAll函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap