Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
ctx.iteratorVals = [{data: 1}, {data: 2}, {data: 3}]
ctx.iterator = createAsyncIterator(ctx.iteratorVals)
ctx.subscribePromise.resolve(ctx.iterator)
})
subscribe: () => createAsyncIterator(array1)
}
'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
}
}
},
.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
}).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) {
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
});
});
});
return executionIterable.then(ei => ({
executionIterable: isAsyncIterable(ei) ? ei : createAsyncIterator([ ei ]),
params,
}));
}).then(({ executionIterable, params }) => {
return executionIterable.then(ei => ({
executionIterable: isAsyncIterable(ei)
? ei
: createAsyncIterator([ei]),
params
}))
})
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(), {
return executionPromise.then(executionResult => ({
executionIterable: isAsyncIterable(executionResult)
? executionResult
: createAsyncIterator([executionResult]),
params,
}));
})