Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I expected the example to be less code. Not more. Other than making it more familiar for C# devs what value does it add?


It pushes the extra code to the function. If you're consuming a library, that's code you never have to write. Even if you are writing the code, it moves the complexity out from your business logic so it can focus on the important things rather than cluttering it up with tidying up resources.


Using libraries we already don't have to write cleanup code. What does the new keyword add that we can't already do? https://node-postgres.com/apis/pool#poolquery


From what I can tell from that documentation, you do still have to remember to call `client.release()`. There's even a big warning saying "You must release a client when you are finished with it."

Presumably you would want to wrap that in a try/finally so that you don't accidentally not release the client if there is an exception.

You would go from:

  const client = await pool.connect()
  try {
    // Do stuff. Possibly throw.
  } finally {
    client.release()
  }
to

  await using client = pool.connect()
  // Do stuff. Possibly throw.


I linked the wrong example. This is the one without having to specifically call release. https://node-postgres.com/apis/pool#poolquery




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: