How to use the @reactivex/rxjs.Observable.throw function in @reactivex/rxjs

To help you get started, we’ve selected a few @reactivex/rxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
.mergeMap((isDefinitelyTyped: boolean): Observable<[number, SymbolInformation]> => {
				// Use special logic for DefinitelyTyped
				// Search only in the correct subdirectory for the given PackageDescriptor
				if (isDefinitelyTyped) {
					// Error if not passed a SymbolDescriptor query with an `@types` PackageDescriptor
					if (!params.symbol || !params.symbol.package || !params.symbol.package.name || !params.symbol.package.name.startsWith('@types/')) {
						return Observable.throw('workspace/symbol on DefinitelyTyped is only supported with a SymbolDescriptor query with an @types PackageDescriptor');
					}

					// Fetch all files in the package subdirectory
					// All packages are in the types/ subdirectory
					const normRootUri = this.rootUri.endsWith('/') ? this.rootUri : this.rootUri + '/';
					const packageRootUri = normRootUri + params.symbol.package.name.substr(1) + '/';

					return Observable.from(this.updater.ensureStructure(span))
						.mergeMap(() => observableFromIterable(this.inMemoryFileSystem.uris()))
						.filter(uri => uri.startsWith(packageRootUri))
						.mergeMap(uri => this.updater.ensure(uri, span))
						.toArray()
						.mergeMap(() => {
							span.log({ event: 'fetched package files' });
							const config = this.projectManager.getParentConfiguration(packageRootUri, 'ts');
							if (!config) {
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
if (item.containerName) {
								symbolInformation.containerName = item.containerName;
							}
							return [score, symbolInformation] as [number, SymbolInformation];
						})
						.filter(([score, symbolInformation]) => isLocalUri(symbolInformation.location.uri));
				} else {
					// An empty query uses a different algorithm to iterate all files and aggregate the symbols per-file to get all symbols
					// TODO make all implementations use this? It has the advantage of being streamable and cancellable
					return observableFromIterable(this._getNavigationTreeItems(config))
						// Same score for all
						.map(symbol => [1, symbol])
						.take(limit);
				}
			} catch (err) {
				return Observable.throw(err);
			}
		})()
			.do(noop, err => {
github kitten / fluorine / test / dispatcher / schedule.js View on Github external
.bufferCount(6)
  ])
    .subscribe(([ x, y ]) => {
      t.same(x, [ 0, 1, 2, 0 ])
      t.same(y, [ 0, -1, -2, -3, -4, -5 ])
    }, err => {
      t.fail()
    }, () => {
      t.end()
    })

  dispatcher.schedule(Observable
    .interval(250)
    .take(2)
    .map(() => add)
    .concat(Observable.throw()))

  dispatcher.schedule(Observable
    .interval(100)
    .take(5)
    .map(() => subtract))
})
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
executeCodeFixCommand(fileTextChanges: ts.FileTextChanges[], span = new Span()): Observable {
		if (fileTextChanges.length === 0) {
			return Observable.throw(new Error('No changes supplied for code fix command'));
		}

		return Observable.from(this.projectManager.ensureOwnFiles(span))
			.mergeMap(() => {
				const configuration = this.projectManager.getConfiguration(fileTextChanges[0].fileName);
				configuration.ensureBasicFiles(span);

				const changes: {[uri: string]: TextEdit[]} = {};
				for (const change of fileTextChanges) {
					const sourceFile = this._getSourceFile(configuration, change.fileName, span);
					if (!sourceFile) {
						throw new Error(`Expected source file ${change.fileName} to exist in configuration`);
					}
					const uri = path2uri(this.root, change.fileName);
					changes[uri] = change.textChanges.map(({ span, newText }): TextEdit => ({
						range: {
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
workspaceExecuteCommand(params: ExecuteCommandParams, span = new Span()): Observable {
		switch (params.command) {
			case 'codeFix':
				if (!params.arguments || params.arguments.length < 1) {
					return Observable.throw(new Error(`Command ${params.command} requires arguments`));
				}
				return this.executeCodeFixCommand(params.arguments, span);
			default:
				return Observable.throw(new Error(`Unknown command ${params.command}`));
		}
	}