{"id":15643161,"url":"https://github.com/aduth/correctinginterval","last_synced_at":"2025-04-15T16:38:33.143Z","repository":{"id":12383790,"uuid":"15035821","full_name":"aduth/correctingInterval","owner":"aduth","description":"An auto-correcting alternative to setInterval","archived":false,"fork":false,"pushed_at":"2017-07-27T21:24:14.000Z","size":78,"stargazers_count":59,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-12T09:55:19.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/aduth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-09T02:09:19.000Z","updated_at":"2024-02-08T10:22:35.000Z","dependencies_parsed_at":"2022-08-30T16:11:30.617Z","dependency_job_id":null,"html_url":"https://github.com/aduth/correctingInterval","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2FcorrectingInterval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2FcorrectingInterval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2FcorrectingInterval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aduth%2FcorrectingInterval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aduth","download_url":"https://codeload.github.com/aduth/correctingInterval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249109730,"owners_count":21214209,"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":[],"created_at":"2024-10-03T11:59:18.364Z","updated_at":"2025-04-15T16:38:33.125Z","avatar_url":"https://github.com/aduth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/aduth/correctingInterval.png?branch=master)](https://travis-ci.org/aduth/correctingInterval)\n\n# correctingInterval\n\ncorrectingInterval exposes two functions, `setCorrectingInterval` and `clearCorrectingInterval`, which serve as drop-in replacements for `setInterval` and `clearInterval`. Unlike `setInterval`, the `setCorrectingInterval` function automatically adjusts to correct subsequent intervals that were delayed due to latency. This is useful if your delayed executions need to occur at predictable intervals. For more information, refer to my related blog post below:\n\n[Creating a self-correcting alternative to JavaScript's setInterval](https://andrewduthie.com/2013/12/31/creating-a-self-correcting-alternative-to-javascripts-setinterval/)\n\n## Usage\n\n### Browser\n\nDownload correctingInterval.js to your project or install using Bower (`bower install correctingInterval`). Include the file using a `\u003cscript\u003e` tag. Then, use with the same syntax as you would use `setInterval`, e.g.:\n\n```javascript\nvar startTime = Date.now();\nsetCorrectingInterval(function() {\n  console.log((Date.now() - startTime) + 'ms elapsed');\n}, 1000);\n```\n\n### RequireJS\n\nDownload correctingInterval.js to your project or install using Bower (`bower install correctingInterval`). Include the file as a dependency to your module. correctingInterval is passed as an object containing the two functions as object members, e.g.:\n\n```javascript\ndefine([\n  'vendor/correctingInterval'\n], function(ci) {\n  var startTime = Date.now();\n  ci.setCorrectingInterval(function() {\n    console.log((Date.now() - startTime) + 'ms elapsed');\n  }, 1000);\n});\n```\n\n### Node.js\n\nInstall correctingInterval using npm (`npm install correcting-interval`). Require correctingInterval in your application script. correctingInterval is passed as an object containing the two functions as object members, e.g.:\n\n```javascript\nvar ci = require('correcting-interval');\n\nvar startTime = Date.now();\nci.setCorrectingInterval(function() {\n  console.log((Date.now() - startTime) + 'ms elapsed');\n}, 1000);\n```\n\n## Clearing Intervals\n\nSimilar to `setInterval`, you can stop running intervals by storing a reference to the value returned by `setCorrectingInterval` and later use as the sole parameter to `clearCorrectingInterval`, e.g.:\n\n```javascript\nvar intervalId = setCorrectingInterval(function() { }, 1000);\n\n// Later in your script...\nclearCorrectingInterval(intervalId);\n```\n\n## License\n\nCopyright 2014 Andrew Duthie.\n\nReleased freely under the MIT license (refer to LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faduth%2Fcorrectinginterval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faduth%2Fcorrectinginterval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faduth%2Fcorrectinginterval/lists"}