How to use the iterall.getAsyncIterator function in iterall

To help you get started, we’ve selected a few iterall 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 michalkvasnicak / aws-lambda-graphql / packages / aws-lambda-graphql / src / MemoryEventProcessor.ts View on Github external
schema: options.schema,
                event: {} as any, // we don't have api gateway event here
                lambdaContext: lambdaContext as any, // we don't have a lambda's context here
                context: options.context,
                connection: subscriber.connection,
                operation: subscriber.operation,
                pubSub,
                registerSubscriptions: false,
              });

              if (!isAsyncIterable(iterable)) {
                // something went wrong, probably there is an error
                return Promise.resolve();
              }

              const iterator = getAsyncIterator(iterable);
              const result: IteratorResult = await iterator.next();

              if (result.value != null) {
                return connectionManager.sendToConnection(
                  subscriber.connection,
                  formatMessage({
                    id: subscriber.operationId,
                    payload: result.value,
                    type: SERVER_EVENT_TYPES.GQL_DATA,
                  }),
                );
              }

              return Promise.resolve();
            })
            .map(promise => promise.catch(e => console.log(e)));
github graphql / graphql-js / src / subscription / mapAsyncIterator.js View on Github external
export default function mapAsyncIterator(
  iterable: AsyncIterable,
  callback: T =&gt; PromiseOrValue<u>,
  rejectCallback?: any =&gt; PromiseOrValue<u>,
): AsyncGenerator {
  const iterator = getAsyncIterator(iterable);
  let $return;
  let abruptClose;
  // $FlowFixMe(&gt;=0.68.0)
  if (typeof iterator.return === 'function') {
    $return = iterator.return;
    abruptClose = error =&gt; {
      const rethrow = () =&gt; Promise.reject(error);
      return $return.call(iterator).then(rethrow, rethrow);
    };
  }

  function mapResult(result) {
    return result.done
      ? result
      : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
  }</u></u>
github michalkvasnicak / aws-lambda-graphql / packages / aws-lambda-graphql / src / DynamoDBEventProcessor.ts View on Github external
schema: options.schema,
                event: lambdaEvent as any, // we don't have an API GW event here
                lambdaContext,
                context: options.context,
                connection: subscriber.connection,
                operation: subscriber.operation,
                pubSub,
                registerSubscriptions: false,
              });

              if (!isAsyncIterable(iterable)) {
                // something went wrong, probably there is an error
                return Promise.resolve();
              }

              const iterator = getAsyncIterator(iterable);
              const result: IteratorResult = await iterator.next();

              if (result.value != null) {
                return connectionManager.sendToConnection(
                  subscriber.connection,
                  formatMessage({
                    id: subscriber.operationId,
                    payload: result.value,
                    type: SERVER_EVENT_TYPES.GQL_DATA,
                  }),
                );
              }

              return Promise.resolve();
            })
            .map(promise =&gt; promise.catch(this.onError));
github graphql / graphql-js / module / subscription / mapAsyncIterator.js View on Github external
export default function mapAsyncIterator(iterable, callback, rejectCallback) {
  var iterator = getAsyncIterator(iterable);
  var $return = void 0;
  var abruptClose = void 0;
  if (typeof iterator.return === 'function') {
    $return = iterator.return;
    abruptClose = function abruptClose(error) {
      var rethrow = function rethrow() {
        return Promise.reject(error);
      };
      return $return.call(iterator).then(rethrow, rethrow);
    };
  }

  function mapResult(result) {
    return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
  }
github DxCx / graphql-rxjs / src / utils.js View on Github external
return Observable.create((observer) => {
    const iterator = getAsyncIterator(asyncIterable);

    const errorHandler = (error) => observer.error(error);
    const nextHandler = (result) => {
      if ( result.done ) {
        observer.complete();
        return;
      }

      observer.next(result.value);
      return iterator.next().then(nextHandler, errorHandler);;
    };

    iterator.next().then(nextHandler, errorHandler);
    return () => {
      if ( typeof iterator.return === 'function' ) {
        iterator.return.call(iterator);