{"id":21658362,"url":"https://github.com/segmentio/timers","last_synced_at":"2025-08-07T10:09:36.803Z","repository":{"id":57484123,"uuid":"117135544","full_name":"segmentio/timers","owner":"segmentio","description":"Go package providing efficient time management primitives.","archived":false,"fork":false,"pushed_at":"2023-06-26T21:18:06.000Z","size":13,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-18T21:39:04.410Z","etag":null,"topics":["paused"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/segmentio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-11T18:12:30.000Z","updated_at":"2023-08-22T17:07:37.000Z","dependencies_parsed_at":"2024-06-18T21:20:06.820Z","dependency_job_id":"4321f0b9-2c54-4c8b-b5f4-830f7c0603f3","html_url":"https://github.com/segmentio/timers","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Ftimers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Ftimers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Ftimers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Ftimers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/segmentio","download_url":"https://codeload.github.com/segmentio/timers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226304629,"owners_count":17603629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["paused"],"created_at":"2024-11-25T09:29:09.548Z","updated_at":"2024-11-25T09:29:15.249Z","avatar_url":"https://github.com/segmentio.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# timers [![CircleCI](https://circleci.com/gh/segmentio/timers.svg?style=shield)](https://circleci.com/gh/segmentio/timers) [![Go Report Card](https://goreportcard.com/badge/github.com/segmentio/timers)](https://goreportcard.com/report/github.com/segmentio/timers) [![GoDoc](https://godoc.org/github.com/segmentio/timers?status.svg)](https://godoc.org/github.com/segmentio/timers)\n\n\u003e **Note**  \n\u003e Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.\n\n## Motivations\n\nThe Go standard library offers good timer management abstractions through the\n[time](https://golang.org/pkg/time/) and [context](https://golang.org/pkg/context/)\npackages. However those are built as general purpose solution to fit most\nprograms out there, but aren't designed for very high performance applications,\nand can become sources of inefficiencies for high traffic services.\n\nTake as an example the common pattern of using `context.WithTimeout` to acquire\na context that will control the time limit for an HTTP request. The creation of\nsuch context constructs a new timer within the Go runtime, and allocates a few\nhundred bytes of memory on the heap. A large portion of the CPU time and memory\nallocation now ends up being spent on creating those timers which in most cases\nwill never fire since the normal behavior is often for the request to succeed\nand not to timeout.\n\nThis is where the `timers` package come in play, offering timing management\nabstractions which are both compatible with code built on top of the standard\nlibrary and designed for efficiency.\n\n## Timelines\n\nTimelines are a key abstraction for efficient timer management. They expose APIs\nto create background contexts that expire on a defined deadline, but instead of\ncreating a new context, it shares contexts that are expire within a same time\nwindow. This means that concurrent operations which are intended to expire at\nroughly the same time do not need to create and manage their own context, they\ncan share one that a timeline has already set for expiration near their own\ndeadline.\n\nThe trade off is on the accuracy of the expirations, when creating a new context\nthe runtime will try its best to expire it exactly at the time it was set for.\nA Timeline on the other hand will use a configurable resolution to group\nexpiration times together under a single timer.\nThere are use cases where a program may want to get timers that are as accurate\nas possible, but often times (and especially to manage request timeouts) the\nprogram will have no issues dealing with a 10 seconds timeout which triggered\nafter 11 seconds instead of 10.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegmentio%2Ftimers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsegmentio%2Ftimers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegmentio%2Ftimers/lists"}