Question arround Using static map of pipeTransport pair PR

This is the PR where @ibc initially started to make global state for pipeTransportPair so that if routerA and routerB tries to do pipeToRouter it will take id of both router and try to check if there is transport already established and available, if available it will reuse the transport pair instead of recreating them.

But plan changed and instead of map of routerA_id-routerB_id to pipeTransportPair he created a map of routerB_id to Promise as suggested by @nazar-pc .

So my question is will this solve the situation when routerA and routerB tries call pipeToRouter at the same time? Because there won’t be a pipeTransportPair for both of the router ids. For eg- if routerA.pipeToRouter(routerB) then there will be an entry in mapRouterPairPipeTransportPairPromise only for routerB.id with Promise and vice versa.

If you read the code carefully, you’ll see that there will always be one transport on each side, there is even a test case just for that.

Still unable to figure out where magic happens after long hour of debugging in vscode. Please care to tell me.

Just go through the function top to bottom and think what happens on every line

   1                 let pipeTransportPairPromise =
   2                         this.#mapRouterPairPipeTransportPairPromise.get(pipeTransportPairKey);
   3                 let pipeTransportPair: PipeTransportPair;
   4                 let localPipeTransport: PipeTransport;
   5                 let remotePipeTransport: PipeTransport;
   6 
   7                 if (pipeTransportPairPromise)
   8                 {
   9                         pipeTransportPair = await pipeTransportPairPromise;
  10                         localPipeTransport = pipeTransportPair[this.id];
  11                         remotePipeTransport = pipeTransportPair[router.id];
  12                 }

So my guess is line number 1 and 9 is where it is decided to use existing transport but still unable to understand that since the router.id will different for both case then how it will get the pipeTransportPairPromise and await for it?

addPipeTransportPair() method.

Hey @nazar-pc sorry. I think I found the trick.

Yeah just found that. Thanks @ibc.