How to use the iterall.createAsyncIterator 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 tjmehta / primus-graphql / src / server / __tests__ / data-handler.unit.js View on Github external
beforeEach(() => {
            ctx.iteratorVals = [{data: 1}, {data: 2}, {data: 3}]
            ctx.iterator = createAsyncIterator(ctx.iteratorVals)
            ctx.subscribePromise.resolve(ctx.iterator)
          })
github ardatan / graphql-toolkit / tests / utils / resolvers-composition.spec.ts View on Github external
'Subscription.foo': (prevAsyncIteratorFactory: any) => (root: any, args: any, context: any, info: any) => {
                const prevAsyncIterator = prevAsyncIteratorFactory(root, args, context, info);
                const newAsyncIterator = createAsyncIterator(array2);
                return {
                    async next() {
                        const { value: v1, done } = await prevAsyncIterator.next();
                        const { value: v2 } = await newAsyncIterator.next();
                        if (!done) {
                            return {
                                value: v1 + v2,
                                done
                            };
                        } else {
                            return {
                                value: undefined,
                                done
                            }
                        }
                    },
github OriginProtocol / origin-playground / src / graphql / links / SubscriptionsLink.js View on Github external
.then(({ executionIterable, params }) => {
              forAwaitEach(createAsyncIterator(executionIterable), value => {
                let result = value
                if (params.formatResponse) {
                  try {
                    result = params.formatResponse(value, params)
                  } catch (err) {
                    console.error('Error in formatError function:', err)
                  }
                }
                sendMessage(opId, MessageTypes.GQL_DATA, result)
              })
                .then(() => {
                  sendMessage(opId, MessageTypes.GQL_COMPLETE, null)
                })
                .catch(e => {
                  let error = e
github PCreations / apollo-link-webworker / src / workerUtils.js View on Github external
}).then(({ executionIterable, params }) => {
              forAwaitEach(
                createAsyncIterator(executionIterable),
                value => {
                  let result = value;
                  if (params.formatResponse) {
                    try {
                      result = params.formatResponse(value, params);
                    } catch (err) {
                      console.error('Error in formatError function:', err);
                    }
                  }
                  sendMessage(opId, MessageTypes.GQL_DATA, result);
                }).then(() => {
                  sendMessage(opId, MessageTypes.GQL_COMPLETE, null);
                }).catch(e => {
                  let error = e;
    
                  if (params.formatError) {
github back4app / antframework / plugins / ant-graphql / spec / lib / util / AsyncIterableObserver.spec.js View on Github external
test('should return async iterator', () => {
    const observer = new AsyncIterableObserver('foo', rxjs.of(1));
    expect(iterall.isAsyncIterable(observer)).toBeTruthy();
    const iterator = iterall.createAsyncIterator(observer);
    expect(iterator.next()).resolves.toEqual({
      value: {
        foo: 1
      },
      done: false
    });
    expect(iterator.next()).resolves.toEqual({
      value: {
        foo: undefined
      },
      done: true
    });
  });
});
github PCreations / apollo-link-webworker / src / workerUtils.js View on Github external
return executionIterable.then(ei => ({
                executionIterable: isAsyncIterable(ei) ? ei : createAsyncIterator([ ei ]),
                params,
              }));
            }).then(({ executionIterable, params }) => {
github OriginProtocol / origin / experimental / origin-graphql / src / links / SubscriptionsLink.js View on Github external
return executionIterable.then(ei => ({
                executionIterable: isAsyncIterable(ei)
                  ? ei
                  : createAsyncIterator([ei]),
                params
              }))
            })
github fanout / fanout-graphql-tools / src / subscriptions-transport-ws-over-http / SubscriptionStoragePubSubMixin.ts View on Github external
const asyncIterator = (triggerName: string | string[]) => {
    const triggerNames = Array.isArray(triggerName)
      ? triggerName
      : [triggerName];
    const ai = createAsyncIterator(
      publishes
        .filter(p => triggerNames.includes(p.triggerName))
        .map(p => p.payload),
    );
    return ai;
  };
  return Object.assign(new PubSub(), {
github fanout / apollo-serverless-demo / src / subscriptions-transport-core / server.ts View on Github external
return executionPromise.then(executionResult => ({
                    executionIterable: isAsyncIterable(executionResult)
                      ? executionResult
                      : createAsyncIterator([executionResult]),
                    params,
                  }));
                })