I built something similar for handling transactions/savepoints in drizzle:
https://github.com/nickdeis/drizzle-transaction-contextOther languages like python and golang have similar concepts, but AsyncLocalStorage has a really nice API suited for async programming. It also pairs really nice with drizzle's savepoint implementation since both AsyncLocalStorage and savepoints can be nested.