Skip to content

Commit

Permalink
feat: track lifecycle for ALL requests, does not matter if nterwork i…
Browse files Browse the repository at this point in the history
…s intercepted or not
  • Loading branch information
nilshah98 committed Nov 24, 2023
1 parent 1cda91c commit 63ec621
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/core/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ export class Network {

if (this.intercept) {
this.#pending.set(requestId, event);
// release request
this.#requestsLifeCycleHandler.get(requestId).releaseRequest();
}
// release request
// note: we are releasing this, even if intercept is not set for network.js
// since, we want to process all-requests in-order doesn't matter if it should be intercepted or not
this.#requestsLifeCycleHandler.get(requestId).releaseRequest();
}

// Called when a pending request is paused. Handles associating redirected requests with
Expand Down Expand Up @@ -221,9 +223,9 @@ export class Network {
// the request data and adds a buffer method to fetch the response body when needed.
_handleResponseReceived = async (session, event) => {
let { requestId, response } = event;
// wait for upto 2 seconds or check if request has been sent
// await on requestWillBeSent
// no explicitly wait on requestWillBePaused as we implictly wait on it, since it manipulates the lifeCycle of request using Fetch module
await Promise.any([this.#requestsLifeCycleHandler.get(requestId).checkRequestSent, new Promise((resolve) => setTimeout(resolve, 2000))]);
await this.#requestsLifeCycleHandler.get(requestId).checkRequestSent;
let request = this.#requests.get(requestId);
/* istanbul ignore if: race condition paranioa */
if (!request) return;
Expand All @@ -250,7 +252,7 @@ export class Network {
_handleLoadingFinished = async event => {
let { requestId } = event;
// wait for upto 2 seconds or check if response has been sent
await Promise.any([this.#requestsLifeCycleHandler.get(requestId).checkResponseSent, new Promise((resolve) => setTimeout(resolve, 2000))]);
await this.#requestsLifeCycleHandler.get(requestId).checkResponseSent;
let request = this.#requests.get(requestId);
/* istanbul ignore if: race condition paranioa */
if (!request) return;
Expand Down

0 comments on commit 63ec621

Please sign in to comment.