mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
split cloudflare/cron.WaitForCompletion from cron.ScheduleTask
This commit is contained in:
parent
5f0fcb01dd
commit
2a59c59bae
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/syumai/workers"
|
||||
"github.com/syumai/workers/internal/jsutil"
|
||||
"github.com/syumai/workers/internal/runtimecontext"
|
||||
)
|
||||
@ -46,14 +47,11 @@ func init() {
|
||||
jsutil.Binding.Set("runScheduler", runSchedulerCallback)
|
||||
}
|
||||
|
||||
//go:wasmimport workers ready
|
||||
func ready()
|
||||
|
||||
// ScheduleTask sets the Task to be executed
|
||||
func ScheduleTask(task Task) {
|
||||
scheduledTask = task
|
||||
ready()
|
||||
select {}
|
||||
workers.Ready()
|
||||
WaitForCompletion()
|
||||
}
|
||||
|
||||
// ScheduleTaskNonBlock sets the Task to be executed but does not signal readiness or block
|
||||
@ -61,3 +59,9 @@ func ScheduleTask(task Task) {
|
||||
func ScheduleTaskNonBlock(task Task) {
|
||||
scheduledTask = task
|
||||
}
|
||||
|
||||
// WaitForCompletion blocks until the task set by ScheduleTaskWithNonBlock is completed.
|
||||
// Currently, this function never returns to support cloudflare.WaitUntil feature.
|
||||
func WaitForCompletion() {
|
||||
select {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user