Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/core/src/global_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,14 @@ pub fn queue_effect(f: impl FnOnce() + 'static) {
///
#[doc = include_str!("../docs/common_spawn_errors.md")]
pub fn spawn_forever(fut: impl Future<Output = ()> + 'static) -> Option<Task> {
Runtime::with_scope(ScopeId::ROOT, |cx| cx.spawn(fut)).ok()
spawn_in_scope(ScopeId::ROOT, fut)
}

/// Spawns a future in the provided scope. This task will automatically be canceled when the component's scope is dropped.
///
#[doc = include_str!("../docs/common_spawn_errors.md")]
pub fn spawn_in_scope(scope: ScopeId, fut: impl Future<Output = ()> + 'static) -> Option<Task> {
Runtime::with_scope(scope, |cx| cx.spawn(fut)).ok()
}

/// Informs the scheduler that this task is no longer needed and should be removed.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub mod prelude {
consume_context, consume_context_from_scope, current_owner, current_scope_id,
fc_to_builder, generation, has_context, needs_update, needs_update_any, parent_scope,
provide_context, provide_error_boundary, provide_root_context, queue_effect, remove_future,
schedule_update, schedule_update_any, spawn, spawn_forever, spawn_isomorphic, suspend,
schedule_update, schedule_update_any, spawn, spawn_forever, spawn_in_scope, spawn_isomorphic, suspend,
throw_error, try_consume_context, use_after_render, use_before_render, use_drop, use_hook,
use_hook_with_cleanup, with_owner, AnyValue, Attribute, Callback, Component,
ComponentFunction, Context, Element, ErrorBoundary, ErrorContext, Event, EventHandler,
Expand Down