How to use the @reactivex/rxjs.Observable.create 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 tarrencev / ethjs / src / contract.js View on Github external
context[name] = (...args) => {
        // Do some arg enforcement
        expectCorrectArgs(args, inputs);
        // Encode ethereum function call transaction
        const encodedTransaction = abiLib.rawEncode(name, buildArgArray(inputs, 'type'), args);
        return Observable.create(observer => {
            ethClient.sendTransaction({
                from: '0xe0743179eaeb698e5e738ec388b0e44fbda8a492',
                data: encodedTransaction.toString('hex'),
                gas: 1000000,
            }).then(
                res => {
                    const txHash = res;
                    observer.next({
                        txHash,
                    });

                    pollWithPromise(ethClient.getTransactionReceipt, 2000, txHash)
                        .then(
                            res => {
                                observer.next(res);
                                observer.complete();
github CasparCG / media-scanner / src / scanner.js View on Github external
module.exports = function ({ config, db, logger }) {
  Observable
    .create(o => {
      const watcher = chokidar
        .watch(config.scanner.paths, Object.assign({
          alwaysStat: true,
          awaitWriteFinish: {
            stabilityThreshold: 2000,
            pollInterval: 1000
          }
        }, config.scanner))
        .on('error', err => logger.error({ err }))
        .on('add', (path, stat) => o.next([ path, stat ]))
        .on('change', (path, stat) => o.next([ path, stat ]))
        .on('unlink', (path, stat) => o.next([ path ]))
      return () => watcher.close()
    })
    // TODO (perf) groupBy + mergeMap with concurrency.
github tarrencev / ethjs / src / contracts.js View on Github external
create(abi, params) {
        return Observable.create(observer => {
            const ethClient = this[ETH_CLIENT];
            ethClient.sendTransaction(params)
                .then(
                    res => {
                        const txHash = res;
                        observer.next({
                            txHash,
                        });

                        pollWithPromise(ethClient.getTransactionReceipt, 2000, txHash)
                            .then(
                                res => {
                                    const { contractAddress } = res;
                                    const contract = new Contract(ethClient, abi, contractAddress);
                                    observer.next(contract);
                                    observer.complete();
github CasparCG / server / node / src / scanner.js View on Github external
module.exports = function ({ config, db, logger }) {
  Observable
    .create(o => {
      const watcher = chokidar
        .watch(config.scanner.paths, {
          alwaysStat: true,
          awaitWriteFinish: {
            stabilityThreshold: 2000,
            pollInterval: 100
          },
          ...config.scanner
        })
        .on('error', err => logger.error({ err }))
        .on('add', (path, stat) => o.next([ path, stat ]))
        .on('change', (path, stat) => o.next([ path, stat ]))
        .on('unlink', (path, stat) => o.next([ path ]))
      return () => watcher.cancel()
    })
github tarrencev / ethjs / src / filters.js View on Github external
export function pollForFilterChanges(ethClient, filterId) {
    return Observable.create(observer => {
        let pollTimeoutId;
        const pollFunc = () =>
            getFilterChanges(ethClient, filterId)
                    .then(
                        ({ result }) => {
                            clearTimeout(pollTimeoutId);
                            observer.next(result);
                            pollTimeoutId  = setTimeout(pollFunc, FILTER_CHANGES_POLL_MS);
                        },
                        err => observer.error(err)
                    );

        pollFunc();
    });
};
github OmniSharp / omnisharp-node-client / lib / helpers / fromCallback.ts View on Github external
return function(...args: any[]) {
        return Observable.create((subscriber: Subscriber) => {
            let cancelled = false;
            function handler(...handlerArgs: any[]) {
                if (cancelled) return;
                if (handlerArgs.length <= 1) {
                    subscriber.next(handlerArgs[0]);
                } else {
                    subscriber.next(handlerArgs);
                }

                subscriber.complete();
            }

            args.push(handler);
            func.apply(null, args);

            return function() { cancelled = true; };
github tarrencev / ethjs / src / utils.js View on Github external
export function pollWithObservable(func, pollTimeoutMS, ...args) {
    return Observable.create(observer => {
        let pollTimeoutId;
        const pollFunc = () =>
            func(...args).then(
                res => {
                    clearTimeout(pollTimeoutId);
                    observer.next(res);
                    pollTimeoutId  = setTimeout(pollFunc, pollTimeoutMS);
                },
                err => observer.error(err)
            );

        pollFunc();
    });
};