rename WaitForCompletion to Done

This commit is contained in:
syumai 2024-11-08 02:33:28 +09:00
parent 87cf65a213
commit 68bb0c7e08
2 changed files with 15 additions and 12 deletions

View File

@ -12,7 +12,10 @@ import (
type Task func(ctx context.Context) error
var scheduledTask Task
var (
scheduledTask Task
doneCh = make(chan struct{})
)
func runScheduler(eventObj js.Value) error {
ctx := runtimecontext.New(context.Background(), eventObj)
@ -51,7 +54,7 @@ func init() {
func ScheduleTask(task Task) {
scheduledTask = task
workers.Ready()
WaitForCompletion()
<-Done()
}
// ScheduleTaskNonBlock sets the Task to be executed but does not signal readiness or block
@ -60,8 +63,8 @@ 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 {}
// Done returns a channel which is closed when the task is done.
// Currently, this channel is never closed to support cloudflare.WaitUntil feature.
func Done() <-chan struct{} {
return doneCh
}

View File

@ -16,7 +16,7 @@ import (
var (
httpHandler http.Handler
closeCh = make(chan struct{})
doneCh = make(chan struct{})
)
func init() {
@ -52,7 +52,7 @@ type appCloser struct {
}
func (c *appCloser) Close() error {
defer close(closeCh)
defer close(doneCh)
return c.ReadCloser.Close()
}
@ -89,7 +89,7 @@ func handleRequest(reqObj js.Value) (js.Value, error) {
func Serve(handler http.Handler) {
ServeNonBlock(handler)
Ready()
WaitForCompletion()
<-Done()
}
// ServeNonBlock sets the http.Handler to be served but does not signal readiness or block
@ -109,7 +109,7 @@ func Ready() {
ready()
}
// WaitForCompletion blocks until the handler set by ServeNonBlock is completed.
func WaitForCompletion() {
<-closeCh
// Done returns a channel which is closed when the handler is done.
func Done() <-chan struct{} {
return doneCh
}