Skip to content

"complete" single fired events? #181

@benlesh

Description

@benlesh

For example, if you have a web socket, and you get a close event, I'm proposing that we just complete it for the user. This of course means identifying different things that are like this and handling them appropriately.

const socket = new WebSocket('wss://whatever');

socket.when('close').subscribe({
  next: () => console.log('closed'),
  complete: () => console.log('done'),
});

AbortSignal's abort is another one I can think of off the top of my head.

Alternatively, users will just have to add a take(1) to them.

But this does illustrate another advantage to Observable over addEventListener. It also causes the subscription to teardown and clean up, which can cascade through flatMap and other composition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions