{"id":20390662,"url":"https://github.com/dizmo/functions-buffered","last_synced_at":"2025-03-05T00:12:43.781Z","repository":{"id":46987547,"uuid":"141465640","full_name":"dizmo/functions-buffered","owner":"dizmo","description":"dizmoFun: buffered invocations","archived":false,"fork":false,"pushed_at":"2023-10-18T13:42:24.000Z","size":1302,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-26T23:03:02.199Z","etag":null,"topics":["buffered","dizmo","function","invocation","javascript","library","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@dizmo/functions-buffered","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dizmo.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-07-18T17:08:09.000Z","updated_at":"2022-11-16T19:00:13.000Z","dependencies_parsed_at":"2024-10-31T22:00:47.024Z","dependency_job_id":null,"html_url":"https://github.com/dizmo/functions-buffered","commit_stats":{"total_commits":149,"total_committers":2,"mean_commits":74.5,"dds":0.01342281879194629,"last_synced_commit":"cedbb6b6e9d803a679f800941ab6c2bbb2f2c733"},"previous_names":[],"tags_count":72,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-buffered","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-buffered/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-buffered/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-buffered/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dizmo","download_url":"https://codeload.github.com/dizmo/functions-buffered/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241940579,"owners_count":20045883,"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":["buffered","dizmo","function","invocation","javascript","library","typescript"],"created_at":"2024-11-15T03:26:11.508Z","updated_at":"2025-03-05T00:12:43.749Z","avatar_url":"https://github.com/dizmo.png","language":"TypeScript","readme":"[![NPM version](https://badge.fury.io/js/%40dizmo%2Ffunctions-buffered.svg)](https://npmjs.org/package/@dizmo/functions-buffered)\n[![Build Status](https://travis-ci.com/dizmo/functions-buffered.svg?branch=master)](https://travis-ci.com/dizmo/functions-buffered)\n[![Coverage Status](https://coveralls.io/repos/github/dizmo/functions-buffered/badge.svg?branch=master)](https://coveralls.io/github/dizmo/functions-buffered?branch=master)\n\n# @dizmo/functions-buffered\n\nReturns a *buffered* and *cancelable* version for the provided function. The buffered function does *not* execute before the specified delay passes upon which it executes exactly **once**, no matter have many times it gets invoked in between.\n\nThe *cancellation* of a particular invocation is only possible while the specified delay has not passed yet. Further, upon the invocation of the buffered function a *promise* is returned.\n\n## Usage\n\n### Install\n\n```sh\nnpm install @dizmo/functions-buffered --save\n```\n\n### Require\n\n```javascript\nconst { buffered } = require(\"@dizmo/functions-buffered\");\n```\n\n### Examples\n\n```typescript\nimport { buffered } from \"@dizmo/functions-buffered\";\n```\n\n```typescript\nlet fn = buffered((t: Date) =\u003e {\n    return new Date().getTime() - t.getTime();\n}, 200);\n\nfn(new Date()).then((res: number) =\u003e {\n    console.debug(res);\n}).catch((err: Error) =\u003e {\n    console.error(err);\n});\n```\n\n```typescript\nlet fn = buffered(() =\u003e {\n    throw new Error(\"won't be thrown\");\n}, 600);\n\nfn().then((res: any) =\u003e { // won't execute!\n    console.debug(res);\n}).catch((err: Error) =\u003e {\n    console.error(err);\n});\n\nfn.cancel();\n```\n\n```typescript\nclass Class {\n    @buffered.decorator(100)\n    public async f1(t: Date): Promise\u003cnumber\u003e {\n        return new Date().getTime() - t.getTime();\n    }\n    @buffered.decorator // 200ms default\n    public async f2(t: Date) {\n        return new Date().getTime() - t.getTime();\n    }\n}\n\nconst p1: Promise\u003cnumber\u003e\n    = new Class().f1(new Date());\nconst p2\n    = new Class().f2(new Date());\n\np1.then((res: number) =\u003e { console.debug(res); });\np2.then((res: number) =\u003e { console.debug(res); });\n```\n\n## Development\n\n### Clean\n\n```sh\nnpm run clean\n```\n\n### Build\n\n```sh\nnpm run build\n```\n\n#### without linting and cleaning:\n\n```sh\nnpm run -- build --no-lint --no-clean\n```\n\n#### with UMD bundling (incl. minimization):\n\n```sh\nnpm run -- build --prepack\n```\n\n#### with UMD bundling (excl. minimization):\n\n```sh\nnpm run -- build --prepack --no-minify\n```\n\n### Lint\n\n```sh\nnpm run lint\n```\n\n#### with auto-fixing:\n\n```sh\nnpm run -- lint --fix\n```\n\n### Test\n\n```sh\nnpm run test\n```\n\n#### without linting, cleaning and (re-)building:\n\n```sh\nnpm run -- test --no-lint --no-clean --no-build\n```\n\n### Cover\n\n```sh\nnpm run cover\n```\n\n#### without linting, cleaning and (re-)building:\n\n```sh\nnpm run -- cover --no-lint --no-clean --no-build\n```\n\n## Documentation\n\n```sh\nnpm run docs\n```\n\n## Publish\n\n```sh\nnpm publish\n```\n\n#### initially (if public):\n\n```sh\nnpm publish --access=public\n```\n\n## Copyright\n\n © 2020 [dizmo AG](http://dizmo.com/), Switzerland\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdizmo%2Ffunctions-buffered","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdizmo%2Ffunctions-buffered","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdizmo%2Ffunctions-buffered/lists"}