Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)));
export default function mapAsyncIterator(
iterable: AsyncIterable,
callback: T => PromiseOrValue<u>,
rejectCallback?: any => PromiseOrValue<u>,
): AsyncGenerator {
const iterator = getAsyncIterator(iterable);
let $return;
let abruptClose;
// $FlowFixMe(>=0.68.0)
if (typeof iterator.return === 'function') {
$return = iterator.return;
abruptClose = error => {
const rethrow = () => 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>
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 => promise.catch(this.onError));
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);
}
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);