Skip to content

AsyncIterator.return() #130

Open
Open
@timoshisa

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.

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