Skip to content

AsyncIterator.return() #130

Description

@timoshisa

How do I get AsyncIterator.return() to get called onDisconnect and on unsubscribe? I'm looking through the code and it seems this will get bypassed whenever the web socket is disconnected or a subscription is unsubscribed...

I'm trying to publish a presence event to a room topic whenever a user goes offline, using this code I found on google:

const withCancel = (asyncIteratorFn, onCancel) => {
  return async (rootValue, args, context, info) => {
    const asyncIterator = await asyncIteratorFn(rootValue, args, context, info);
    const asyncIteratorReturn = asyncIterator.return;

    asyncIterator.return = () => {
      onCancel();
      return asyncIteratorReturn
        ? asyncIteratorReturn.call(asyncIterator)
        : Promise.resolve({ value: undefined, done: true });
    };

    return asyncIterator;
  };
};

But asyncIterator.return is never called, and so it doesn't invoke my onCancel event to publish.

Would be willing to submit a PR if you can point me in the right direction.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions