Skip to main content

set_scope_store

Function set_scope_store 

Source
pub fn set_scope_store(store: ScopeStore) -> Result<(), ScopeStore>
Expand description

Install a custom scope store.

Must be called before any scope operations (i.e. before any TaskScope::new, current_scope, etc.). On Wasm or in tests the default thread-local store is sufficient.

Returns Ok(()) on success, or Err(store) if a store was already installed (either by a previous call to this function or via [init_scope_store_tokio]).

§Errors

Returns the provided store back inside Err if the global store has already been initialised. This happens when set_scope_store or [init_scope_store_tokio] was called previously, or when any scope operation (e.g. TaskScope::new) has already triggered the default thread-local store installation.

§Example (tokio SSR)

use auralis_task::ScopeStore;

auralis_task::set_scope_store(ScopeStore {
    set_fn: my_tokio_task_local_set,
    get_fn: my_tokio_task_local_get,
}).expect("scope store already initialised");