All challenges

TypeScript · medium

One client

#31

Situation

getClient() opens a new connection on every call. The pool reached 400 before lunch, even though callers should be able to share one client.

Objective

Reuse one client across calls. Two results from getClient() must be the same object reference, so the pool does not keep growing.

The repo at start

workspace/
└── src/
    └── db.ts   (new client every call; pool crying)

Checks you will turn green

  • exports getClient
  • getClient returns a client
  • two getClient calls share a reference

Concepts

modulesreferences

Play it in your terminal

With sharpen installed, this command opens exactly this challenge in your local arena:

sharpen 31

First time? The full install is right below.

How to play

  1. 1 Install Claude Code if you do not have it yet: claude.com/claude-code
  2. 2 Install sharpen from npm:
    npm install -g @juanwmedia/sharpen
  3. 3 Then launch it; the arena opens in your browser:
    sharpen 31
  4. or Or try it without installing anything:
    npx @juanwmedia/sharpen 31
  5. 4 And to update when a new version ships:
    sharpen update