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"
|
"fmt"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
|
|
||||||
|
"github.com/syumai/workers"
|
||||||
"github.com/syumai/workers/internal/jsutil"
|
"github.com/syumai/workers/internal/jsutil"
|
||||||
"github.com/syumai/workers/internal/runtimecontext"
|
"github.com/syumai/workers/internal/runtimecontext"
|
||||||
)
|
)
|
||||||
@ -46,14 +47,11 @@ func init() {
|
|||||||
jsutil.Binding.Set("runScheduler", runSchedulerCallback)
|
jsutil.Binding.Set("runScheduler", runSchedulerCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:wasmimport workers ready
|
|
||||||
func ready()
|
|
||||||
|
|
||||||
// ScheduleTask sets the Task to be executed
|
// ScheduleTask sets the Task to be executed
|
||||||
func ScheduleTask(task Task) {
|
func ScheduleTask(task Task) {
|
||||||
scheduledTask = task
|
scheduledTask = task
|
||||||
ready()
|
workers.Ready()
|
||||||
select {}
|
WaitForCompletion()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScheduleTaskNonBlock sets the Task to be executed but does not signal readiness or block
|
// 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) {
|
func ScheduleTaskNonBlock(task Task) {
|
||||||
scheduledTask = 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