{"analyzedAt":"2022-07-03T21:43:52.577Z","collected":{"metadata":{"name":"chunked-call","scope":"unscoped","version":"1.0.1","description":"Split blocking execution to small chunks.","keywords":["typescript","chunks","chunked","async","execution"],"date":"2018-08-21T22:45:12.175Z","author":{"name":"Piotr Paczkowski","email":"kontakt@trzeci.eu","username":"trzeci.eu"},"publisher":{"username":"trzeci.eu","email":"kontakt@trzeci.eu"},"maintainers":[{"username":"trzeci.eu","email":"kontakt@trzeci.eu"}],"repository":{"type":"git","url":"git+https://github.com/trzecieu/chunked-call.git"},"links":{"npm":"https://www.npmjs.com/package/chunked-call","homepage":"https://trzecieu.github.io/chunked-call/","repository":"https://github.com/trzecieu/chunked-call","bugs":"https://github.com/trzecieu/chunked-call/issues"},"license":"MIT","devDependencies":{"@types/jest":"^23.3.1","jest":"^23.5.0","prettier":"^1.14.2","ts-jest":"^23.1.3","tslint":"^5.11.0","tslint-config-prettier":"^1.14.0","typescript":"^3.0.1"},"releases":[{"from":"2022-06-03T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":0},{"from":"2022-04-04T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":1},{"from":"2022-01-04T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":1},{"from":"2021-07-03T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":1},{"from":"2020-07-03T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":1}],"hasTestScript":true,"readme":"# chunked-call\r\n[![NPM version](https://img.shields.io/npm/v/chunked-call.svg)](https://www.npmjs.com/package/chunked-call) [![Build Status](https://travis-ci.org/trzecieu/chunked-call.svg?branch=master)](https://travis-ci.org/trzecieu/chunked-call)\r\n\r\nThis package helps you split blocking - time consuming operations to chunks that are executed in an asynchronous manner.\r\nThe package was inspired long time ago, by a [StackOverflow Question](https://stackoverflow.com/questions/44669648/asynchronous-callback-javascript-with-complex-calculation) and main usage should be for systems where multi-threading operations are not available. \r\n\r\n## Demo\r\nPlease visit [demo](https://trzecieu.github.io/chunked-call/) page to see examples.\r\n\r\n## Usage\r\n### Installation\r\nPackage is available on npm repository: `npm i chunked-call -D`\r\n\r\n### API\r\n```ts\r\n// Callback to execution code\r\ndeclare type IChunkedCallTask = () => boolean;\r\n// Callback on finishing execution\r\ndeclare type IChunkedCallCallback = () => void;\r\n\r\n// Starts Chunked Call\r\n// @task: callback to function that executes until it returns false. \r\n// @callback: called when execution is finished.\r\n// @limitMs: once execution time exceeded given time, it waits to a next frame\r\n// return: Handler to Chunked Call executor, can be used to terminate execution\r\nfunction setChunkedCall(task: IChunkedCallTask, callback?: IChunkedCallCallback, limitMs?: number): number;\r\n\r\n// Promisified version of setChunkedCall\r\nfunction setChunkedCallPromise(task: IChunkedCallTask, limitMs?: number): Promise<void>;\r\n\r\n// Terminates execution of ongoing chunked call\r\n// @id: Identifier of chunked call gotten from setChunkedCall\r\n// return: True if an execution has been killed successfully, false otherwise.\r\nfunction killChunkedCall(id: number): boolean;\r\n```\r\n\r\n### How to implement chunked-call?\r\n#### Import required functions\r\n```js\r\nlet setChunkedCall = require(\"chunked-call\").setChunkedCall;\r\nlet killChunkedCall = require(\"chunked-call\").killChunkedCall;\r\n```\r\n\r\n#### Case: Loop `for`\r\n```js\r\n// original code:\r\nfor (let i = 0; i < array.length; i++) {\r\n    doSomeOperation(array[i]);\r\n}\r\nnextStep();\r\n\r\n// becomes:\r\nsetChunkedCall(\r\n    (() => {\r\n        let i = 0;\r\n        return () => {\r\n            i++;\r\n            doSomeOperation(array[i]);\r\n            return i < array.length;\r\n        }\r\n    })(), \r\n    () => nextStep()\r\n);\r\n```\r\n\r\n#### Case: Loop `while`\r\n```js\r\n// original code:\r\nwhile (array.length) {\r\n    doSomeOperation(array.pop());\r\n}\r\nnextStep();\r\n\r\n// becomes:\r\nsetChunkedCall(\r\n    () => {\r\n        if (array.length) {\r\n            doSomeOperation(array.pop());\r\n        }\r\n        return array.length;\r\n    }, \r\n    () => nextStep()\r\n);\r\n```\r\n\r\n#### Case: Loop `do-while`\r\n```js\r\n// original code:\r\ndo {\r\n    doSomeOperation(array.pop());\r\n}\r\nwhile (array.length);\r\nnextStep();\r\n\r\n\r\n// becomes:\r\nsetChunkedCall(\r\n    () => {\r\n        doSomeOperation(array.pop());\r\n        return array.length > 0;\r\n    }, \r\n    () => nextStep()\r\n);\r\n```\r\n\r\n## Changelog\r\n- `1.0.0` - Version uses `setTimeout` and `claerTimeout` to schedule next execution\r\n- `0.0.6` - Added Travis CI\r\n- `0.0.5` - Updated documentation\r\n- `0.0.4` - Improve test coverage\r\n- `0.0.3` - Updated documentation\r\n- `0.0.2` - First release\r\n\r\n## License\r\n[MIT](LICENSE)"},"npm":{"downloads":[{"from":"2022-07-02T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":0},{"from":"2022-06-26T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":2},{"from":"2022-06-03T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":12},{"from":"2022-04-04T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":70},{"from":"2022-01-04T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":144},{"from":"2021-07-03T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":317}],"starsCount":0},"github":{"starsCount":0,"forksCount":0,"subscribersCount":1,"issues":{"count":0,"openCount":0,"distribution":{"3600":0,"10800":0,"32400":0,"97200":0,"291600":0,"874800":0,"2624400":0,"7873200":0,"23619600":0,"70858800":0,"212576400":0},"isDisabled":false},"contributors":[{"username":"trzecieu","commitsCount":19}],"commits":[{"from":"2022-06-26T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":0},{"from":"2022-06-03T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":0},{"from":"2022-04-04T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":0},{"from":"2022-01-04T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":0},{"from":"2021-07-03T00:00:00.000Z","to":"2022-07-03T00:00:00.000Z","count":0}],"statuses":[{"context":"continuous-integration/travis-ci/push","state":"success"}]},"source":{"files":{"readmeSize":3200,"testsSize":1796,"hasNpmIgnore":true},"badges":[{"urls":{"original":"https://img.shields.io/npm/v/chunked-call.svg","shields":"https://img.shields.io/npm/v/chunked-call.svg","content":"https://img.shields.io/npm/v/chunked-call.json"},"info":{"service":"npm","type":"version","modifiers":{"type":"v"}}},{"urls":{"original":"https://travis-ci.org/trzecieu/chunked-call.svg?branch=master","service":"https://api.travis-ci.org/trzecieu/chunked-call.svg?branch=master","shields":"https://img.shields.io/travis/trzecieu/chunked-call/master.svg","content":"https://img.shields.io/travis/trzecieu/chunked-call/master.json"},"info":{"service":"travis","type":"build","modifiers":{"branch":"master"}}}],"linters":["prettier","tslint"]}},"evaluation":{"quality":{"carefulness":0.9199999999999999,"tests":0.85,"health":1,"branding":0.7},"popularity":{"communityInterest":2,"downloadsCount":23.333333333333332,"downloadsAcceleration":-0.13424657534246573,"dependentsCount":0},"maintenance":{"releasesFrequency":0.9,"commitsFrequency":0.9,"openIssues":0.9,"issuesDistribution":0.9}},"score":{"final":0.6494052369708744,"detail":{"quality":0.9703963139431937,"popularity":0.02379443115066378,"maintenance":0.9998808339576686}}}