Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split Done funcs from workers.Serve / cron.ScheduleTask #132

Merged
merged 6 commits into from
Nov 7, 2024

Conversation

syumai
Copy link
Owner

@syumai syumai commented Nov 7, 2024

What

  • Add workers.ServeNonBlock, workers.Done, workers.Ready and cron.Done funcs.

Motivation

  • Support HTTP Request and Cron Trigger in Single Worker #130 introduced a non-blocking version of cron.ScheduleTask.
    • A non-blocking version of workers.Serve is also needed, so this PR adds it.
  • Additionally, the workers package provides a public Ready() function.
    • It can be used as a common ready signal function.
  • The Done() function can be used to wait for a handler or a task to complete.

Usage

func main() {
	// declare handler and task here ...

	// set up the worker
	workers.ServeNonBlock(handler)
	cron.ScheduleTaskNonBlock(task)

	// send a ready signal to the runtime
	workers.Ready()

	// block until the handler or task is done
	select {
	case <-workers.Done():
	case <-cron.Done():
	}
}

@syumai syumai self-assigned this Nov 7, 2024
@syumai syumai marked this pull request as ready for review November 7, 2024 17:40
@syumai syumai merged commit 605532b into main Nov 7, 2024
2 checks passed
@syumai syumai deleted the split-wait-for-ready-from-serve branch November 7, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant