Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove listeners on close() #34

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ export class Connection extends Entity {
}

/**
* Removes the provided session from the internal map.
* Removes the provided session from the internal map in rhea.
* Also removes all the event handlers added in the rhea-promise library on the provided session.
* @param {Session} session The session to be removed.
*/
removeSession(session: Session): void {
Expand Down Expand Up @@ -377,7 +378,9 @@ export class Connection extends Entity {
}

/**
* Remove all the sessions from the internal map.
* Clears all the amqp sessions from the internal map maintained in rhea. This does not remove any
* of the event handlers added in the rhea-promise library. To clear such event handlers, either
* call remove() or close() on each session
*/
removeAllSessions(): void {
if (this._connection) {
Expand Down
7 changes: 5 additions & 2 deletions lib/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export abstract class Link extends Entity {
}

/**
* Removes the sender/receiver and it's underlying session from the internal map.
* Removes the underlying amqp link and it's session from the internal map in rhea. Also removes
* all the event handlers added in the rhea-promise library on the link and it's session.
* @returns {void} void
*/
remove(): void {
Expand All @@ -207,13 +208,15 @@ export abstract class Link extends Entity {
}

/**
* Closes the amqp link.
* Closes the underlying amqp link and session in rhea if open. Also removes all the event
* handlers added in the rhea-promise library on the link and it's session
* @return {Promise<void>} Promise<void>
* - **Resolves** the promise when rhea emits the "sender_close" | "receiver_close" event.
* - **Rejects** the promise with an AmqpError when rhea emits the
* "sender_error" | "receiver_error" event while trying to close the amqp link.
*/
async close(): Promise<void> {
this.removeAllListeners();
await new Promise<void>((resolve, reject) => {
log.error("[%s] The %s is open ? -> %s", this.connection.id, this.type, this.isOpen());
if (this.isOpen()) {
Expand Down
8 changes: 7 additions & 1 deletion lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export class Session extends Entity {
return this._session.is_itself_closed();
}

/**
* Removes the underlying amqp session from the internal map in rhea.
* Also removes all the event handlers added in the rhea-promise library on the session.
*/
remove(): void {
if (this._session) {
// Remove our listeners and listeners from rhea's 'session' object.
Expand All @@ -100,13 +104,15 @@ export class Session extends Entity {
}

/**
* Closes the amqp session.
* Closes the underlying amqp session in rhea if open. Also removes all the event
* handlers added in the rhea-promise library on the session
* @return {Promise<void>} Promise<void>
* - **Resolves** the promise when rhea emits the "session_close" event.
* - **Rejects** the promise with an AmqpError when rhea emits the "session_error" event while trying
* to close an amqp session.
*/
close(): Promise<void> {
this.removeAllListeners();
return new Promise<void>((resolve, reject) => {
log.error("[%s] The session is open ? -> %s", this.connection.id, this.isOpen());
if (this.isOpen()) {
Expand Down