{"id":15675214,"url":"https://github.com/nylen/wait-until","last_synced_at":"2025-05-06T21:49:27.171Z","repository":{"id":21420918,"uuid":"24739019","full_name":"nylen/wait-until","owner":"nylen","description":"Simple Node.js library to wait until a condition has been satisfied.","archived":false,"fork":false,"pushed_at":"2018-07-19T20:59:56.000Z","size":144,"stargazers_count":13,"open_issues_count":5,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T04:37:36.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nylen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-02T22:24:15.000Z","updated_at":"2022-03-29T09:52:23.000Z","dependencies_parsed_at":"2022-08-21T08:11:07.989Z","dependency_job_id":null,"html_url":"https://github.com/nylen/wait-until","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylen%2Fwait-until","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylen%2Fwait-until/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylen%2Fwait-until/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylen%2Fwait-until/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nylen","download_url":"https://codeload.github.com/nylen/wait-until/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776506,"owners_count":21802463,"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-03T15:57:40.366Z","updated_at":"2025-05-06T21:49:27.077Z","avatar_url":"https://github.com/nylen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wait-until [![Build status](https://img.shields.io/travis/nylen/wait-until.svg?style=flat)](https://travis-ci.org/nylen/wait-until) [![npm package](http://img.shields.io/npm/v/wait-until.svg?style=flat)](https://www.npmjs.org/package/wait-until)\n\nThis simple Node.js module provides a way to check for a condition every so\noften, then run a callback after the condition is met or the allotted time\nexpires.\n\nThis is good if you need to wait for specific state changes in code that you\ndon't have direct control over, like a headless web browser.\n\n## Usage\n\n```js\nvar waitUntil = require('wait-until');\n\nwaitUntil(interval, times, function condition() {\n    return (someCondition ? true : false);\n}, function done(result) {\n    // result is true on success or false if the condition was never met\n});\n```\n\nThe `condition` function will be called up to `times` times, starting after\n`interval` milliseconds.  Once it returns `true` (or a truthy value), the\n`done` callback will be called with `result` equal to `true` (or whatever value\nthe `condition` function returned).\n\nIf the condition is never met within the specified timeframe, `done` will be\ncalled with `result` equal to `false` (or whatever falsy value the `condition`\nfunction returned the last time it was called).\n\n### Fluent interface\n\n**Don't want to remember the order of arguments?**  Then use the\n[fluent interface](https://en.wikipedia.org/wiki/Fluent_interface):\n\n```js\nvar waitUntil = require('wait-until');\n\nwaitUntil()\n    .interval(500)\n    .times(10)\n    .condition(function() {\n        return (someCondition ? true : false);\n    })\n    .done(function(result) {\n        // do stuff\n    });\n```\n\n### Async conditions\n\nIf the `condition` function accepts an argument, then it is assumed to be a\ncallback function which will be called with the result of the test:\n\n```js\nvar waitUntil = require('wait-until');\n\nwaitUntil()\n    .interval(500)\n    .times(10)\n    .condition(function(cb) {\n        process.nextTick(function() {\n            cb(someCondition ? true : false);\n        });\n    })\n    .done(function(result) {\n        // do stuff\n    });\n```\n\n### Other notes\n\nYou can specify `.times(Infinity)` if you like, but it's probably better to set\nand enforce a reasonable timeout.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnylen%2Fwait-until","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnylen%2Fwait-until","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnylen%2Fwait-until/lists"}