Skip to content

Commit a66fb67

Browse files
committed
stop more cleanly
1 parent 0eefd10 commit a66fb67

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/api/instagram.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,11 @@ export class Instagram<PostType> {
334334
protected async stop() {
335335
await this.progress(Progress.CLOSING);
336336

337-
// Close page and browser
337+
// Remove listeners
338338
if (!this.page.isClosed()) {
339339
this.page.removeAllListeners("request");
340340
this.page.removeAllListeners("response");
341341
this.page.removeAllListeners("requestfailed");
342-
await this.page.close();
343-
}
344-
if (this.finished && !this.browserDisconnected) {
345-
await this.browser.close();
346342
}
347343

348344
// Clear request buffers
@@ -354,6 +350,15 @@ export class Instagram<PostType> {
354350
await this.responseBufferLock.acquireAsync();
355351
this.responseBuffer = [];
356352
this.responseBufferLock.release();
353+
354+
// Close page
355+
if (!this.page.isClosed()) {
356+
await this.page.close();
357+
}
358+
359+
if (this.finished && !this.browserDisconnected) {
360+
await this.browser.close();
361+
}
357362
}
358363

359364
/**

src/api/search.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ export class Search extends Instagram<TSearchResult> {
126126
await this.stop();
127127
throw e;
128128
}
129-
130129
await this.stop();
131130
return this.searchResult;
132131
}

0 commit comments

Comments
 (0)