We first do server.listen and then server.close. However if there is an error in between, the server will never be closed and interception of requests will continue. server.close should always be called, and the default way of doing is to use try / finally. However, this is going to make the code way less readable.
In this code:
https://github.com/arda-org/xSuite/blob/ac3c108c656cebe2bd4e2cd79064b15688d4bfb2/xsuite/src/cli/cli.test.ts#L295-L301
We first do
server.listen
and thenserver.close
. However if there is an error in between, the server will never be closed and interception of requests will continue.server.close
should always be called, and the default way of doing is to use try / finally. However, this is going to make the code way less readable.We could rather use
using
:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management
The idea is to create an helper that returns and object that has this method containing the cleanup logic: