{"id":20516171,"url":"https://github.com/aftership/node-tmfy","last_synced_at":"2026-05-08T08:35:13.362Z","repository":{"id":66356441,"uuid":"73458922","full_name":"AfterShip/node-tmfy","owner":"AfterShip","description":null,"archived":false,"fork":false,"pushed_at":"2016-11-17T07:06:59.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-02-17T03:03:09.226Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AfterShip.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":"2016-11-11T08:18:31.000Z","updated_at":"2016-11-11T10:49:38.000Z","dependencies_parsed_at":"2023-02-22T06:30:54.559Z","dependency_job_id":null,"html_url":"https://github.com/AfterShip/node-tmfy","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Fnode-tmfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Fnode-tmfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Fnode-tmfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Fnode-tmfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AfterShip","download_url":"https://codeload.github.com/AfterShip/node-tmfy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242119218,"owners_count":20074712,"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-11-15T21:27:07.249Z","updated_at":"2026-05-08T08:35:13.319Z","avatar_url":"https://github.com/AfterShip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tmfy\n\n[![node](https://img.shields.io/node/v/tmfy.svg)]()\n[![npm](https://img.shields.io/npm/v/tmfy.svg)]()\n[![npm](https://img.shields.io/npm/l/tmfy.svg)]()\n\nTimeouts for promises and promisified functions\n\n**Pronunciation**: timeify, `Thai-Me-Fy`\n\n## Quick Start\n```\nnpm install tmfy\n```\n\n```javascript\nvar tmfy = require('tmfy');\n\nvar lib = {\n\tsendEmail: function(send_to) {\n\t\t// need 200ms to send\n\t\treturn new Promise(function (r) { setTimeout(r, 200) });\n\t},\n\tsendEmailSlowly: function(send_to) {\n\t\t// need 20000ms to send\n\t\treturn new Promise(function (r) { setTimeout(r, 20000) });\n\t}\n};\n\ntmfy.timeifyAll(lib);\n\nlib.sendEmailTimeout(1000, 'me@apple.com') // timeout after 1000ms\n\t.then(function(result) {\n\t\tconsole.log('email sent');\n\t})\n\t.catch(function(error) {\n\t\t// never called\n\t});\n\nlib.sendEmailSlowlyTimeout(1000, 'me@apple.com') // timeout after 1000ms\n\t.then(function(result) {\n\t\t// never called\n\t})\n\t.catch(function(error) {\n\t\tconsole.log('timeout first');\n\t});\n```\n\n## API\n\n#### timeout(mil, promise)\n#### timeout(mil, handler, promise)\n\nReturns a Promise.\n- Resolves if `promise` is resolved before `mil`ms timeout. `promise` result is passed.\n- Rejects if `promise` is rejected before `mil`ms timeout. `promise` error is passed.\n- Rejects with `new Error('TIMEOUT')` if `mil`ms timeout before `promise` is resolved or rejected.\n\nIf `handler` is set and have `emit()`, `error` event will be emitted on timeout with `new Error('TIMEOUT')`.\n\n#### timeify(func)\n\n`func` must returns a Promise.\n\nReturns a wrapped function around `func` which accepts `mil` as a first argument:\n```javascript\nvar funcTimeout = tmfy.timeify(func);\nfuncTimeout(1000, ...); // runs func(...) with 1000ms timeout\n```\n\nA wrapped function returns a Promise. Same logic as for `timeout()` applies.\nIf `this` is set and have `emit()`, `error` event will be emitted on timeout with `new Error('TIMEOUT')`.\n\n#### timeifyAll(obj)\n\nExtends `obj` with timeified versions of all functions. Adds 'Timeout' suffix to wrapped functions.\n```javascript\nvar obj = {\n\tfunc: function() { return Promise.resolve('success'); }\n};\ntmfy.timeifyAll(obj);\nobj.funcTimeout(1000)\n\t.then(function(result) {\n\t\t// prints \"success\"\n\t\tresult =\u003e console.log(result)\n\t})\n```\n\n## License\nCopyright (c) 2016 AfterShip\n\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftership%2Fnode-tmfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faftership%2Fnode-tmfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftership%2Fnode-tmfy/lists"}