default class extends WorkerEntrypoint { async fetch() { return new Response("Hello World"); } async newCounter() { let value = 0; return (increment = 0) => { value += increment; return value; }; } } # worker2 > wrangler.toml name = "client_worker" main = "./src/clientWorker.js" services = [ { binding = "COUNTER_SERVICE", service = "counter-service" } ] // worker2.ts export default { async fetch(request, env) { using f = await env.COUNTER_SERVICE.newCounter(); await f(2); // returns 2 await f(1); // returns 3 const count = await f(-5); // returns -2 return new Response(count); }, }; 13