How to use the rx.Observable.create function in rx

To help you get started, we’ve selected a few rx 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 dralletje / cycle-firebase / src / firebase.js View on Github external
errors$.onNext(error)
            })
          }
        } else {
          baseRef.child(location).set(value)
        }

      })
    })

    // Get an observable over the current uid of the user
    let auth$ = authToObservable(baseRef)
    let uid$ = auth$.map(x => x ? x.uid : null)

    // Get an observable that will complete with one random ID
    let pushId$ = Observable.create(observer => {
      observer.onNext(pushId())
      observer.onCompleted()
      return () => {}
    })

    // Small utility to wrap objects in a 'set' object
    let $set = object => {
      return { $set: object }
    }

    // Prevents errors when getting using an empty path
    let getFbChild = (ref, location) =>
      location === `` ? ref : ref.child(location)

    let specialCaseListeners = {
      // Current user as observable
github Exynize / exynize-rest / src / runner / serviceWithRabbit.js View on Github external
    return (data) => Observable.create(obs => {
        let cachedConsumerTag;
        // generate unique ID for current transaction
        const id = uuid.v4();
        const topic = 'runner.result.' + id;
        // return by type mapping
        const returnByType = {
            result: obs.onNext.bind(obs),
            error: obs.onError.bind(obs),
            done: obs.onCompleted.bind(obs),
        };
        const runCommand = async () => {
            cachedConsumerTag = await service.subscribe(topic, (msg) => {
                // log
                logger.debug('[svc]: got message:', msg.type, 'for:', id);
                // return depending on type
                returnByType[msg.type](msg.data);
github tsers-js / core / test / transducers.js View on Github external
it("returns the rest of output as a second parameter stream", done => {
      const [{listDecomposeLatest}] = TSERS({A: tsersDriver})
      let n = 0
      const sBy = val =>
        O.of({key: "A", val: "a" + n + val}, {key: "B", val: "b" + n + val})

      const in$ = O.create(o => {
        n++
        o.onNext([4, 1, 5])
        setTimeout(() => {
          n++
          o.onNext([2, 5, 3])
        }, 0)
      })

      const [_, rest$] = listDecomposeLatest(in$, sBy, "A")
      rest$.should.be.instanceof(O)
      rest$.bufferWithTime(100).first().subscribe(x => {
        x.should.deepEqual([
          {key: "B", val: "b14"},
          {key: "B", val: "b11"},
          {key: "B", val: "b15"},
          {key: "B", val: "b22"},
github milankinen / stanga / test / model.js View on Github external
function run(MD, main) {
  let obs = null
  const [out, loop] = main(MD(O.create(o => (obs = o) && (() => obs = null))))
  return out.merge(loop.delay(0).filter(x => obs && obs.onNext(x) && false))
}
github angular / tactical / modules / tactical / src / link.ts View on Github external
constructor() {
    this.observable = Observable.create((observer: Observer) => {
      this.observer = observer;
      return () => { this.onDisconnect(); };
    });
  }
github OmniSharp / omnisharp-node-client / lib / omnisharp-runtime.ts View on Github external
        .flatMap(isCurrent => Observable.create((observer) => {
            if (!isCurrent) {
                require("rimraf")(dest, (err: any) => {
                    if (err) { observer.onError(err); return; }

                    delay(() =>
                        fs.mkdir(dest, (er) => {
                            if (er) { observer.onError(er); return; }
                            fs.writeFile(join(dest, ".version"), serverVersion, (e) => {
                                if (e) { observer.onError(e); return; }
                                observer.onNext(null);
                                observer.onCompleted();
                            });
                        }), 500);
                });
                return;
            }
github jike-engineering / mongo-es / src / processor.ts View on Github external
tail(): Observable {
    return Observable.create(observer => {
      try {
        const cursor = this.mongodb.getOplog()
        cursor.forEach(
          (log: OpLog) => {
            observer.onNext(log)
          },
          () => {
            observer.onCompleted()
          },
        )
      } catch (err) {
        observer.onError(err)
      }
    })
  }
github OmniSharp / omnisharp-node-client / lib / candidate-finder.ts View on Github external
export function ifEmpty(observable: Observable, other: Observable) {
    return Observable.create(observer => {
        var hasValue = false;
        var cd = new CompositeDisposable();
        cd.add(observable.subscribe(
            value => {
                hasValue = true;
                observer.onNext(value);
            },
            e => observer.onError(e),
            () => {
                if (!hasValue) {
                    cd.add(other.subscribe(
                        value => observer.onNext(value),
                        e => observer.onError(e),
                        () => observer.onCompleted()
                    ));
                } else {
github CanopyTax / rxws / src / request.js View on Github external
export default function makeRequest(config) {
	if (!backendSet && !mockRequests) throw new Error('Must define a websocket backend');

	return Observable.create((observer) => {
		let request = generateRequestObject(defaultHeaders)(config);

		prepareRequest(observer, request);
	})
}
github CanopyTax / rxws / src / request.js View on Github external
export function use() {
	return Observable.create((observer) => {
		let defaultMiddleware = useMiddlewareQueue.pop();
		useMiddlewareQueue.push(observer);
		useMiddlewareQueue.push(defaultMiddleware);
	});
}