From beb006f8e730c9de3ec3deaaeed71317d1c6ac9f Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 2 Jun 2023 15:39:29 +0900 Subject: [PATCH] Introduce some new `Schedule` operation for explicit nesting. --- lib/async/task.rb | 2 +- lib/kernel/schedule.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 lib/kernel/schedule.rb diff --git a/lib/async/task.rb b/lib/async/task.rb index 72a7c70f..6c5337fb 100644 --- a/lib/async/task.rb +++ b/lib/async/task.rb @@ -234,7 +234,7 @@ def stop(later = false) # @returns [Task] # @raises[RuntimeError] If task was not {set!} for the current fiber. def self.current - Thread.current[:async_task] or raise RuntimeError, "No async task available!" + Thread.current[:async_task] or raise RuntimeError, "No parent async task set!" end # Check if there is a task defined for the current fiber. diff --git a/lib/kernel/schedule.rb b/lib/kernel/schedule.rb new file mode 100644 index 00000000..713ae165 --- /dev/null +++ b/lib/kernel/schedule.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2019-2022, by Samuel Williams. + +require_relative "../async/reactor" + +module Kernel + def Schedule(...) + ::Async::Task.current.async(...) + end +end