AsyncLocalStorage

@JSImport("async_hooks", "AsyncLocalStorage") @native @JSType class AsyncLocalStorage[T]() extends StObject

When having multiple instances of AsyncLocalStorage, they are independent from each other. It is safe to instantiate this class multiple times.

trait StObject
class Object
trait Any
class Object
trait Matchable
class Any

Value members

Concrete methods

def disable(): Unit

This method disables the instance of AsyncLocalStorage. All subsequent calls to asyncLocalStorage.getStore() will return undefined until asyncLocalStorage.run() is called again.

This method disables the instance of AsyncLocalStorage. All subsequent calls to asyncLocalStorage.getStore() will return undefined until asyncLocalStorage.run() is called again.

When calling asyncLocalStorage.disable(), all current contexts linked to the instance will be exited.

Calling asyncLocalStorage.disable() is required before the asyncLocalStorage can be garbage collected. This does not apply to stores provided by the asyncLocalStorage, as those objects are garbage collected along with the corresponding async resources.

This method is to be used when the asyncLocalStorage is not in use anymore in the current process.

def enterWith(store: T): Unit

Calling asyncLocalStorage.enterWith(store) will transition into the context for the remainder of the current synchronous execution and will persist through any following asynchronous calls.

Calling asyncLocalStorage.enterWith(store) will transition into the context for the remainder of the current synchronous execution and will persist through any following asynchronous calls.

def exit[R](callback: Function1[Any, R], args: Any*): R

This methods runs a function synchronously outside of a context and return its return value. The store is not accessible within the callback function or the asynchronous operations created within the callback.

This methods runs a function synchronously outside of a context and return its return value. The store is not accessible within the callback function or the asynchronous operations created within the callback.

Optionally, arguments can be passed to the function. They will be passed to the callback function.

If the callback function throws an error, it will be thrown by exit too. The stacktrace will not be impacted by this call and the context will be re-entered.

def getStore(): UndefOr[T]

This method returns the current store. If this method is called outside of an asynchronous context initialized by calling asyncLocalStorage.run, it will return undefined.

This method returns the current store. If this method is called outside of an asynchronous context initialized by calling asyncLocalStorage.run, it will return undefined.

def run[R](store: T, callback: Function1[Any, R], args: Any*): R

This methods runs a function synchronously within a context and return its return value. The store is not accessible outside of the callback function or the asynchronous operations created within the callback.

This methods runs a function synchronously within a context and return its return value. The store is not accessible outside of the callback function or the asynchronous operations created within the callback.

Optionally, arguments can be passed to the function. They will be passed to the callback function.

I the callback function throws an error, it will be thrown by run too. The stacktrace will not be impacted by this call and the context will be exited.

Inherited methods

def hasOwnProperty(v: String): Boolean
Inherited from
Object
def isPrototypeOf(v: Object): Boolean
Inherited from
Object
def propertyIsEnumerable(v: String): Boolean
Inherited from
Object
def toLocaleString(): String
Inherited from
Object
def valueOf(): Any
Inherited from
Object