import type { Future, Operation, Scope } from "./types.js"; /** * The root of all Effection Scopes. * @since 4.0 */ export declare const global: Scope; /** * Create a new {@link Scope} as a child of `parent`, inheriting all its contexts. * along with a method to destroy the scope. Whenever the scope is destroyd, all * tasks and resources it contains will be halted. * * This function is used mostly by frameworks as an intergration point to enter * Effection. * * @example * ```js * import { createScope, sleep, suspend } from "effection"; * * let [scope, destroy] = createScope(); * * let delay = scope.run(function*() { * yield* sleep(1000); * }); * scope.run(function*() { * try { * yield* suspend(); * } finally { * console.log('done!'); * } * }); * await delay; * await destroy(); // prints "done!"; * ``` * * `createScope()` also supports explicit resource management * @example * ```js * { * await using scope = createScope(); * * let delay = scope.run(function*() { * yield* sleep(1000); * }); * * scope.run(function*() { * try { * yield* suspend(); * } finally { * console.log('done!'); * } * }); * * await delay; * // prints "done!"; * } * ``` * * @param parent scope. If no parent is specified it will derive directly from {@link global} * @returns a tuple containing the freshly created scope, along with a function to * destroy it. * @since 3.0 */ export declare function createScope(parent?: Scope): Scope & AsyncDisposable & [Scope, () => Future]; /** * Get the scope of the currently running {@link Operation}. * * @example * ```ts * import { sleep, useScope } from "effection"; * * let scope = yield* useScope(); * let task = yield* scope.spawn(function* () { * yield* sleep(100); * return "done"; * }); * * // task is attached to the current scope and cannot outlive it * console.log(yield* task); * ``` * * @returns an operation yielding the current scope * @since 3.0 */ export declare function useScope(): Operation;