{"id":24654059,"url":"https://github.com/btoo/noverlap","last_synced_at":"2026-05-15T23:10:09.784Z","repository":{"id":65464422,"uuid":"140022224","full_name":"btoo/noverlap","owner":"btoo","description":"prevent function invocations (both sync and async) from redundantly overlapping with each other","archived":false,"fork":false,"pushed_at":"2020-12-24T05:19:58.000Z","size":49,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T10:21:23.759Z","etag":null,"topics":["asynchronous-programming","debouncing","javascript","memoization","throttling"],"latest_commit_sha":null,"homepage":"","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/btoo.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}},"created_at":"2018-07-06T19:20:33.000Z","updated_at":"2023-03-08T12:28:01.000Z","dependencies_parsed_at":"2023-01-24T17:05:14.806Z","dependency_job_id":null,"html_url":"https://github.com/btoo/noverlap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btoo%2Fnoverlap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btoo%2Fnoverlap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btoo%2Fnoverlap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/btoo%2Fnoverlap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/btoo","download_url":"https://codeload.github.com/btoo/noverlap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717342,"owners_count":20498283,"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":["asynchronous-programming","debouncing","javascript","memoization","throttling"],"created_at":"2025-01-25T21:15:10.490Z","updated_at":"2026-05-15T23:10:04.752Z","avatar_url":"https://github.com/btoo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# noverlap\ndependency-less-ly prevent function invocations (both sync and async) from redundantly overlapping with each other\n\n## usage\n\nfirst import `noverlap`\n```bash\nyarn add noverlap\n```\n```js\nimport noverlap from 'noverlap';\n```\n\nthen instantiate a `noverlap` instance\n```js\nconst throttle = noverlap();\n```\n\nor instantiate `noverlap` with custom configurations:\n- `hash`: a function that generate a hash given the wrapped function's arguments\n- `comparator`: a function that determines whether or not a hash has already been added as a key when looking through the map's keys. useful for when you've lost the reference to certain keys (eg storing objects or arrays as keys). defaults to the [`sameValueZero` algorithm which is used by `Map.prototype.has`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)\n\n- `wait`: the timer duration in milliseconds that will start on each execution of an async function and reset with every overlapping execution\n- `start`: a callback (provided with the wrapped function's arguments) that will be synchronously executed right before the wrapped function\n- `queue`: a callback that gets fired when a function execution has been added to the queue that will be eventually flushed\n- `beforeFinish`: a callback that gets fired right before the wrapped function finally gets called and the queue gets flushed\n- `success`: a callback that gets fired when the redundantly invoked function was resolved\n- `fail`: a callback that gets fired when the redundantly invoked function was rejected\n- `finish`: a callback (provided with the return value of the wrapped function) that will be fired after the wrapped function\n\nthe following are the default configurations:\n```js\nconst defaultThrottle = noverlap({\n  /** the first parameter will be considered the hash of the function execution */\n  hash: (...args) =\u003e args[0],\n\n  /** find a direct reference to the hash that will be looked up as the key in map.get(key) */\n  comparator: (hash, existingKey) =\u003e { /* 'SameValueZero' algorithm */ },\n\n  /** wait 420ms to see if another execution of the async function is overlapping with an existing one */\n  wait: 420,\n})\n```\n\nthe following are not included by default but can be added manually during `noverlap` instantiation (these manual additions get merged with the default configurations)\n```js\nconst customThrottle = noverlap({\n  start(payload) { console.log('a function has just been hashed', payload) },\n  beforeFinish(payload) { console.log('about to execute the function with a payload of', payload) },\n  finish(returnValue) { console.log('the redundantly invoked function returned', returnValue) },\n});\n```\n\nyou can also use a function or promise that is provided with the wrapped function's parameters to construct a `noverlap` instance's configs\n```js\nconst throttle = noverlap((...args) =\u003e /* noverlap configs */);\nconst throttle = noverlap(async (...args) =\u003e /* noverlap configs */);\n```\n\nlet's use this dummy async function that we pretend makes a fetch to a server. we do not want this fetcher to make the same call multiple times in a row when in fact we only need the data from the latest call, which should return the most up to date response\n```js\nconst dummyFetcher = payload =\u003e new Promise((resolve, reject) =\u003e setTimeout(() =\u003e resolve(payload)));\n```\n\napply the noverlap instance to an async function by wrapping it\n```js\nconst throttle = noverlap();\nconst fetchSomeData = throttle(async payload =\u003e {\n  const response = await dummyFetcher(payload);\n  console.log('this async function will only be executed once even if it is called with the same payload multiple times within 420ms');\n  return response;\n});\n```\n\nnow, using `fetchSomeData` like this:\n```js\nconst redundantAsyncExecution = async n =\u003e console.log(\n  `result from execution #${n} with a redundantly repeated fetch using ${\n    await fetchSomeData('this payload')\n  } 🤯`\n);\nredundantAsyncExecution(1);\nredundantAsyncExecution(2);\nredundantAsyncExecution(3);\n```\n\nwill log:\n```\nthis async function will only be executed once even if it is called with the same payload multiple times within 420ms\nresult from execution #1 with a redundantly repeated fetch using this payload 🤯\nresult from execution #2 with a redundantly repeated fetch using this payload 🤯\nresult from execution #3 with a redundantly repeated fetch using this payload 🤯\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbtoo%2Fnoverlap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbtoo%2Fnoverlap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbtoo%2Fnoverlap/lists"}