{"id":22382433,"url":"https://github.com/jcoreio/poll","last_synced_at":"2025-06-18T15:39:35.829Z","repository":{"id":27624824,"uuid":"114683717","full_name":"jcoreio/poll","owner":"jcoreio","description":"yet another promise-based poller","archived":false,"fork":false,"pushed_at":"2024-10-03T16:51:21.000Z","size":602,"stargazers_count":1,"open_issues_count":19,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-10T02:14:55.238Z","etag":null,"topics":["es2015"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-12-18T20:16:18.000Z","updated_at":"2024-10-03T16:51:24.000Z","dependencies_parsed_at":"2024-04-09T04:32:56.777Z","dependency_job_id":"6f0e0392-04d5-4dd2-bd27-48c5bbd38030","html_url":"https://github.com/jcoreio/poll","commit_stats":{"total_commits":122,"total_committers":3,"mean_commits":"40.666666666666664","dds":0.05737704918032782,"last_synced_commit":"b0c9cf2fe1416717ecb67b0b91b444d9ece2477f"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpoll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpoll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpoll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpoll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/poll/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228209939,"owners_count":17885595,"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":["es2015"],"created_at":"2024-12-05T00:12:59.981Z","updated_at":"2024-12-05T00:13:00.638Z","avatar_url":"https://github.com/jcoreio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# poll\n\n[![Build Status](https://travis-ci.org/jcoreio/poll.svg?branch=master)](https://travis-ci.org/jcoreio/poll)\n[![Coverage Status](https://codecov.io/gh/jcoreio/poll/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/poll)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\nyet another promise-based poller (I didn't like the API design of others out there)\n\n## Example\n\n```sh\nnpm install --save @jcoreio/poll\n```\n\n```js\nconst poll = require('@jcoreio/poll')\nconst superagent = require('superagent')\n\npoll(() =\u003e superagent.get('http://google.com'), 1000)\n  .timeout(30000)\n  .then(() =\u003e console.log(\"You're connected to the internet!\"))\n```\n\n## `poll(fn, interval, [options])`\n\nBegins calling `fn` every `interval` milliseconds until the condition passes\n(which defaults to `fn` didn't throw an `Error` or return a rejected `Promise`).\n\nReturns a `Promise` that resolves when polling finishes or fails, which may be:\n\n- when `fn` calls the `pass` method provided to it\n- when `fn` calls the `fail` method provided to it\n- when `fn` returns/resolves to a value or throws/rejects with an `Error` that\n  passes the condition\n- when a timeout is specified and `poll` times out waiting for any of the above\n\n`fn` will be called with a context object:\n\n```js\n{\n  attemptNumber: number, // the number of this call (starting from 0)\n  elapsedTime: number, // the number of milliseconds since polling started\n  pass: (value: any) =\u003e void, // makes `poll` resolve immediately with this value\n  fail: (error: Error) =\u003e void, // makes `poll` reject immediately with this Error\n}\n```\n\nYou can change the condition by calling `.until` on the returned `Promise`:\n\n```js\npoll(...).until((error, result) =\u003e result \u003e 3)\n```\n\n`error` will be the `Error` from the last call to `fn` (if it rejected or threw)\nand `result` will be the value it resolved to or returned otherwise.\n\nYou can specify a timeout (in milliseconds) by calling `.timeout` on the returned `Promise`:\n\n```js\npoll(...).timeout(30000) // time out after 30 seconds\n```\n\nIf you call `.noWrapError()` on the returned `Promise`, it won't wrap rejection errors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fpoll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fpoll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fpoll/lists"}