Skip to content

Feat: Use Time Ticker #4

@audipasuatmadi

Description

@audipasuatmadi

Problem

After a discussion with @kompiangg, it seems we're better-off to use time.Ticker instead of time.Sleep. This is for these reasons:

  • Much more appropriate in an interval-based recurring loop.
  • It uses channel, allows us to enable things like context cancellation called from another goroutine.

This has in theory nothing to do with performance, just for convenient on handling the context cancellation in the future.
Both time.Sleep and time.Ticker only suspends the goroutine (green threads). The Go scheduler removes it from the Run queue to prevent the consumption of CPU resources.

The OS Thread meanwhile isn't blocked by the suspended goroutine as the Go scheduler will reassign the OS Thread to another goroutine. Sort of a context-switching at the green-thread level.

Reference:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions