Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fibrelite

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fibrelite - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

examples/example.js

2

dist/fibrelite.js

@@ -1,2 +0,2 @@

module.exports=function(t,e,n){var o=this,r=[];this.roundRobin=0,this.totalThreads=e||1,this.debounce=n||333,this.totalThreads>20&&(this.totalThreads=20);var s=function(t){o.cachedObjectUrl||(o.cachedObjectUrl=URL.createObjectURL(new Blob(["onmessage=("+function(t){return function(e){Promise.resolve(e.data[1]).then(t.apply.bind(t,t)).then(function(t){postMessage([e.data[0],0,t])},function(t){postMessage([t.data[0],1,""+t])})}}+")("+t+")"])));var e=new Worker(o.cachedObjectUrl),n=0,r={};e.onmessage=function(t){r[t.data[0]][t.data[1]](t.data[2]),r[t.data[0]]=null};var s={resolved:!1,worker:e,fn:function(t){return t=[].slice.call(arguments),new Promise(function(){s.resolved=!1,r[++n]=arguments,e.postMessage([n,t])}).then(function(t){return s.resolved=!0,t})}};return s};this.debounceExecute=function(t){return new Promise(function(e,n){var o=this;return this.latestValue=t,e(new Promise(function(e,n){(void 0===o.batchEnds||Date.now()>=o.batchEnds)&&(o.batchEnds=Date.now()+o.debounce),o.latestValue=t,new Promise(function(){setTimeout(function(){o.latestValue!==t&&void 0!==o.lastExecution||(o.lastExecution=o.execute(t).then(function(t){return o.lastKnownResult=t,t}),e(o.lastExecution)),void 0!==o.lastKnownResult&&e(Promise.resolve(o.lastKnownResult)),e(o.lastExecution)},o.batchEnds-Date.now())})}))}.bind(o))},this.prioritiseExecute=function(t){return new Promise(function(e,n){return r.length>0&&!1===r[this.totalThreads-1].resolved&&r.pop().worker.terminate(),e(this.execute(t))}.bind(o))},this.execute=function(e){return new Promise(function(n,o){for(;r.length<this.totalThreads;)r.unshift(s(t));var i=r[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1||this.roundRobin++,n(i)}.bind(o))},this.getCurrentWorker=function(){return currentThread.worker}};
module.exports=function(t,e,n){var o=this,r=[];this.roundRobin=0,this.totalThreads=e||1,this.debounce=n||333,this.totalThreads>20&&(this.totalThreads=20);var i=function(t){o.cachedObjectUrl||(o.cachedObjectUrl=URL.createObjectURL(new Blob(["onmessage=("+function(t){return function(e){Promise.resolve(e.data[1]).then(t.apply.bind(t,t)).then(function(t){postMessage([e.data[0],0,t])},function(t){postMessage([t.data[0],1,""+t])})}}+")("+t+")"])));var e=new Worker(o.cachedObjectUrl),n=0,r={};e.onmessage=function(t){r[t.data[0]][t.data[1]](t.data[2]),r[t.data[0]]=null};var i={resolved:!1,worker:e,fn:function(t){return t=[].slice.call(arguments),new Promise(function(){i.resolved=!1,r[++n]=arguments,e.postMessage([n,t])}).then(function(t){return i.resolved=!0,t})}};return i};this.debounceExecute=function(t){return new Promise(function(e,n){var o=this;return this.latestValue=t,e(new Promise(function(e,n){(void 0===o.batchEnds||Date.now()>=o.batchEnds)&&(o.batchEnds=Date.now()+o.debounce),o.latestValue=t,new Promise(function(){setTimeout(function(){o.latestValue!==t&&void 0!==o.lastExecution||(o.lastExecution=o.execute(t).then(function(t){return o.lastKnownResult=t,t}),e(o.lastExecution)),void 0!==o.lastKnownResult&&e(Promise.resolve(o.lastKnownResult)),e(o.lastExecution)},o.batchEnds-Date.now())})}))}.bind(o))},this.prioritiseExecute=function(t){return new Promise(function(e,n){return this.terminateAll(),e(this.execute(t))}.bind(o))},this.execute=function(e){return new Promise(function(n,o){for(;r.length<this.totalThreads;)r.unshift(i(t));var s=r[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1?this.roundRobin=0:this.roundRobin++,n(s)}.bind(o))},this.getCurrentWorker=function(){return currentThread.worker},this.terminateAll=function(){r.length>0&&!1===r[o.totalThreads-1].resolved&&r.pop().worker.terminate()}};
//# sourceMappingURL=fibrelite.js.map

@@ -1,2 +0,2 @@

export default function(t,e,n){var o=this,r=[];this.roundRobin=0,this.totalThreads=e||1,this.debounce=n||333,this.totalThreads>20&&(this.totalThreads=20);var s=function(t){o.cachedObjectUrl||(o.cachedObjectUrl=URL.createObjectURL(new Blob(["onmessage=("+function(t){return function(e){Promise.resolve(e.data[1]).then(t.apply.bind(t,t)).then(function(t){postMessage([e.data[0],0,t])},function(t){postMessage([t.data[0],1,""+t])})}}+")("+t+")"])));var e=new Worker(o.cachedObjectUrl),n=0,r={};e.onmessage=function(t){r[t.data[0]][t.data[1]](t.data[2]),r[t.data[0]]=null};var s={resolved:!1,worker:e,fn:function(t){return t=[].slice.call(arguments),new Promise(function(){s.resolved=!1,r[++n]=arguments,e.postMessage([n,t])}).then(function(t){return s.resolved=!0,t})}};return s};this.debounceExecute=function(t){return new Promise(function(e,n){var o=this;return this.latestValue=t,e(new Promise(function(e,n){(void 0===o.batchEnds||Date.now()>=o.batchEnds)&&(o.batchEnds=Date.now()+o.debounce),o.latestValue=t,new Promise(function(){setTimeout(function(){o.latestValue!==t&&void 0!==o.lastExecution||(o.lastExecution=o.execute(t).then(function(t){return o.lastKnownResult=t,t}),e(o.lastExecution)),void 0!==o.lastKnownResult&&e(Promise.resolve(o.lastKnownResult)),e(o.lastExecution)},o.batchEnds-Date.now())})}))}.bind(o))},this.prioritiseExecute=function(t){return new Promise(function(e,n){return r.length>0&&!1===r[this.totalThreads-1].resolved&&r.pop().worker.terminate(),e(this.execute(t))}.bind(o))},this.execute=function(e){return new Promise(function(n,o){for(;r.length<this.totalThreads;)r.unshift(s(t));var i=r[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1||this.roundRobin++,n(i)}.bind(o))},this.getCurrentWorker=function(){return currentThread.worker}};
export default function(t,e,n){var o=this,r=[];this.roundRobin=0,this.totalThreads=e||1,this.debounce=n||333,this.totalThreads>20&&(this.totalThreads=20);var i=function(t){o.cachedObjectUrl||(o.cachedObjectUrl=URL.createObjectURL(new Blob(["onmessage=("+function(t){return function(e){Promise.resolve(e.data[1]).then(t.apply.bind(t,t)).then(function(t){postMessage([e.data[0],0,t])},function(t){postMessage([t.data[0],1,""+t])})}}+")("+t+")"])));var e=new Worker(o.cachedObjectUrl),n=0,r={};e.onmessage=function(t){r[t.data[0]][t.data[1]](t.data[2]),r[t.data[0]]=null};var i={resolved:!1,worker:e,fn:function(t){return t=[].slice.call(arguments),new Promise(function(){i.resolved=!1,r[++n]=arguments,e.postMessage([n,t])}).then(function(t){return i.resolved=!0,t})}};return i};this.debounceExecute=function(t){return new Promise(function(e,n){var o=this;return this.latestValue=t,e(new Promise(function(e,n){(void 0===o.batchEnds||Date.now()>=o.batchEnds)&&(o.batchEnds=Date.now()+o.debounce),o.latestValue=t,new Promise(function(){setTimeout(function(){o.latestValue!==t&&void 0!==o.lastExecution||(o.lastExecution=o.execute(t).then(function(t){return o.lastKnownResult=t,t}),e(o.lastExecution)),void 0!==o.lastKnownResult&&e(Promise.resolve(o.lastKnownResult)),e(o.lastExecution)},o.batchEnds-Date.now())})}))}.bind(o))},this.prioritiseExecute=function(t){return new Promise(function(e,n){return this.terminateAll(),e(this.execute(t))}.bind(o))},this.execute=function(e){return new Promise(function(n,o){for(;r.length<this.totalThreads;)r.unshift(i(t));var s=r[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1?this.roundRobin=0:this.roundRobin++,n(s)}.bind(o))},this.getCurrentWorker=function(){return currentThread.worker},this.terminateAll=function(){r.length>0&&!1===r[o.totalThreads-1].resolved&&r.pop().worker.terminate()}};
//# sourceMappingURL=fibrelite.m.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.fibrelite=t()}(this,function(){return function(e,t,n){var o=this,r=[];this.roundRobin=0,this.totalThreads=t||1,this.debounce=n||333,this.totalThreads>20&&(this.totalThreads=20);var i=function(e){o.cachedObjectUrl||(o.cachedObjectUrl=URL.createObjectURL(new Blob(["onmessage=("+function(e){return function(t){Promise.resolve(t.data[1]).then(e.apply.bind(e,e)).then(function(e){postMessage([t.data[0],0,e])},function(e){postMessage([e.data[0],1,""+e])})}}+")("+e+")"])));var t=new Worker(o.cachedObjectUrl),n=0,r={};t.onmessage=function(e){r[e.data[0]][e.data[1]](e.data[2]),r[e.data[0]]=null};var i={resolved:!1,worker:t,fn:function(e){return e=[].slice.call(arguments),new Promise(function(){i.resolved=!1,r[++n]=arguments,t.postMessage([n,e])}).then(function(e){return i.resolved=!0,e})}};return i};this.debounceExecute=function(e){return new Promise(function(t,n){var o=this;return this.latestValue=e,t(new Promise(function(t,n){(void 0===o.batchEnds||Date.now()>=o.batchEnds)&&(o.batchEnds=Date.now()+o.debounce),o.latestValue=e,new Promise(function(){setTimeout(function(){o.latestValue!==e&&void 0!==o.lastExecution||(o.lastExecution=o.execute(e).then(function(e){return o.lastKnownResult=e,e}),t(o.lastExecution)),void 0!==o.lastKnownResult&&t(Promise.resolve(o.lastKnownResult)),t(o.lastExecution)},o.batchEnds-Date.now())})}))}.bind(o))},this.prioritiseExecute=function(e){return new Promise(function(t,n){return r.length>0&&!1===r[this.totalThreads-1].resolved&&r.pop().worker.terminate(),t(this.execute(e))}.bind(o))},this.execute=function(t){return new Promise(function(n,o){for(;r.length<this.totalThreads;)r.unshift(i(e));var s=r[this.roundRobin].fn(t);return this.roundRobin>=this.totalThreads-1||this.roundRobin++,n(s)}.bind(o))},this.getCurrentWorker=function(){return currentThread.worker}}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.fibrelite=e()}(this,function(){return function(t,e,n){var o=this,i=[];this.roundRobin=0,this.totalThreads=e||1,this.debounce=n||333,this.totalThreads>20&&(this.totalThreads=20);var r=function(t){o.cachedObjectUrl||(o.cachedObjectUrl=URL.createObjectURL(new Blob(["onmessage=("+function(t){return function(e){Promise.resolve(e.data[1]).then(t.apply.bind(t,t)).then(function(t){postMessage([e.data[0],0,t])},function(t){postMessage([t.data[0],1,""+t])})}}+")("+t+")"])));var e=new Worker(o.cachedObjectUrl),n=0,i={};e.onmessage=function(t){i[t.data[0]][t.data[1]](t.data[2]),i[t.data[0]]=null};var r={resolved:!1,worker:e,fn:function(t){return t=[].slice.call(arguments),new Promise(function(){r.resolved=!1,i[++n]=arguments,e.postMessage([n,t])}).then(function(t){return r.resolved=!0,t})}};return r};this.debounceExecute=function(t){return new Promise(function(e,n){var o=this;return this.latestValue=t,e(new Promise(function(e,n){(void 0===o.batchEnds||Date.now()>=o.batchEnds)&&(o.batchEnds=Date.now()+o.debounce),o.latestValue=t,new Promise(function(){setTimeout(function(){o.latestValue!==t&&void 0!==o.lastExecution||(o.lastExecution=o.execute(t).then(function(t){return o.lastKnownResult=t,t}),e(o.lastExecution)),void 0!==o.lastKnownResult&&e(Promise.resolve(o.lastKnownResult)),e(o.lastExecution)},o.batchEnds-Date.now())})}))}.bind(o))},this.prioritiseExecute=function(t){return new Promise(function(e,n){return this.terminateAll(),e(this.execute(t))}.bind(o))},this.execute=function(e){return new Promise(function(n,o){for(;i.length<this.totalThreads;)i.unshift(r(t));var s=i[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1?this.roundRobin=0:this.roundRobin++,n(s)}.bind(o))},this.getCurrentWorker=function(){return currentThread.worker},this.terminateAll=function(){i.length>0&&!1===i[o.totalThreads-1].resolved&&i.pop().worker.terminate()}}});
//# sourceMappingURL=fibrelite.umd.js.map

@@ -150,10 +150,3 @@ export default function fibrelite(asyncFunction, totalThreads, debounce) {

if (pool.length > 0) {
if (pool[this.totalThreads - 1].resolved === false) {
// Remove the worker from the pool
// and terminate it
pool.pop().worker.terminate();
}
}
this.terminateAll();
return this.execute(value);

@@ -171,3 +164,3 @@

if (this.roundRobin >= this.totalThreads - 1) {
this.roundRobin = 0;
} else {

@@ -184,3 +177,15 @@ this.roundRobin++;

this.terminateAll = () => {
if (pool.length > 0) {
if (pool[this.totalThreads - 1].resolved === false) {
// Remove the worker from the pool
// and terminate it
pool.pop().worker.terminate();
}
}
}
}
{
"name": "fibrelite",
"version": "1.0.1",
"version": "1.0.2",
"source": "fibrelite.js",

@@ -5,0 +5,0 @@ "main": "dist/fibrelite.js",

# Fibrelite
Seamlessly use Web Workers to offload UI blocking work. With fibrelite you can turn any async function into a Web Worker.
Seamlessly use [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) to offload work that could block user interaction and page rendering.
Fibrelite has three core approaches to handling work:
With fibrelite you can turn any async function into a Web Worker. Fibrelite has three core approaches to handling work:

@@ -11,2 +11,26 @@ * Execute: Execute an async function as a Web Worker

## Example
Check out fibrelite in action [here](https://jamesmilneruk.github.io/fibrelite/).
## Install
For npm:
```
npm install fibrelite
```
Or for yarn:
```
yarn add fibrelite
```
## TODO:
* Tests
* More use cases / examples
* Performance review
## Acknowledgements

@@ -13,0 +37,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc