11import { MaybePromise } from 'p-map' ;
22
3- import { waitUntil , getGlobalContext } from './waitUntil' ;
3+ import { waitUntil , getRequestContext } from './waitUntil' ;
44
55/**
66 * Execute a function for each input in parallel and return the first result.
@@ -238,7 +238,7 @@ export function singleton<R>(execute: () => Promise<R>): () => Promise<R> {
238238 }
239239
240240 // Promises are not shared between requests in Cloudflare Workers
241- const ctx = await getGlobalContext ( ) ;
241+ const ctx = await getRequestContext ( ) ;
242242 const current = states . get ( ctx ) ;
243243 if ( current ) {
244244 return current ;
@@ -269,7 +269,7 @@ export function singletonMap<Key extends string, Args extends any[], Result>(
269269 const states = new WeakMap < object , Map < string , Promise < Result > > > ( ) ;
270270
271271 const fn : SingletonFunction < Key , Args , Result > = async ( key , ...args ) => {
272- const ctx = await getGlobalContext ( ) ;
272+ const ctx = await getRequestContext ( ) ;
273273 let current = states . get ( ctx ) ;
274274 if ( current ) {
275275 const existing = current . get ( key ) ;
@@ -292,7 +292,7 @@ export function singletonMap<Key extends string, Args extends any[], Result>(
292292 } ;
293293
294294 fn . isRunning = async ( key : string ) => {
295- const ctx = await getGlobalContext ( ) ;
295+ const ctx = await getRequestContext ( ) ;
296296 const current = states . get ( ctx ) ;
297297 return current ?. has ( key ) ?? false ;
298298 } ;
0 commit comments