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.0 to 1.0.1

index.html

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 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.waitExecute=function(e){return new Promise(function(n,o){var s=this;return this.latestValue=e,r.length||(r[0]=i(t)),n(new Promise(function(t,n){(!s.nextBatch||Date.now()>=s.nextBatch)&&(s.nextBatch=Date.now()+s.debounce),s.latestValue=e;var o=s.nextBatch-Date.now();new Promise(function(){setTimeout(function(){s.latestValue!==e&&void 0!==s.lastExecution||(s.lastExecution=s.execute(e).then(function(t){return s.lastKnownResult=t,t}),t(s.lastExecution)),void 0!==s.lastKnownResult&&t(Promise.resolve(s.lastKnownResult)),t(s.lastExecution)},o)})}))}.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(i(t));var s=r[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1||this.roundRobin++,n(s)}.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 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}};
//# 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 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.waitExecute=function(e){return new Promise(function(n,o){var s=this;return this.latestValue=e,r.length||(r[0]=i(t)),n(new Promise(function(t,n){(!s.nextBatch||Date.now()>=s.nextBatch)&&(s.nextBatch=Date.now()+s.debounce),s.latestValue=e;var o=s.nextBatch-Date.now();new Promise(function(){setTimeout(function(){s.latestValue!==e&&void 0!==s.lastExecution||(s.lastExecution=s.execute(e).then(function(t){return s.lastKnownResult=t,t}),t(s.lastExecution)),void 0!==s.lastKnownResult&&t(Promise.resolve(s.lastKnownResult)),t(s.lastExecution)},o)})}))}.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(i(t));var s=r[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1||this.roundRobin++,n(s)}.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 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}};
//# sourceMappingURL=fibrelite.m.js.map

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

!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,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.waitExecute=function(e){return new Promise(function(n,o){var s=this;return this.latestValue=e,r.length||(r[0]=i(t)),n(new Promise(function(t,n){(!s.nextBatch||Date.now()>=s.nextBatch)&&(s.nextBatch=Date.now()+s.debounce),s.latestValue=e;var o=s.nextBatch-Date.now();new Promise(function(){setTimeout(function(){s.latestValue!==e&&void 0!==s.lastExecution||(s.lastExecution=s.execute(e).then(function(t){return s.lastKnownResult=t,t}),t(s.lastExecution)),void 0!==s.lastKnownResult&&t(Promise.resolve(s.lastKnownResult)),t(s.lastExecution)},o)})}))}.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(i(t));var s=r[this.roundRobin].fn(e);return this.roundRobin>=this.totalThreads-1||this.roundRobin++,n(s)}.bind(o))},this.getCurrentWorker=function(){return currentThread.worker}}});
!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}}});
//# sourceMappingURL=fibrelite.umd.js.map

@@ -76,3 +76,3 @@ const dataProcessingAsync = async (input) => {

const fibril = new fibrelite(dataProcessingAsync, 4, 333);
const fibril = new fibrelite(dataProcessingAsync, 4, 500);
const getStringBytes = fibril.debounceExecute;

@@ -111,3 +111,3 @@

stats.domElement.style.top = "0";
stats.domElement.style.right = "0";
stats.domElement.style.left = "0";
stats.domElement.style.width = 80 * 2;

@@ -138,2 +138,7 @@ stats.domElement.style.height = 48 * 2;

setupStats();
setupStats();
document.getElementById("refresh").addEventListener("click", () => {
location.reload();
});

@@ -96,17 +96,15 @@ export default function fibrelite(asyncFunction, totalThreads, debounce) {

this.nextBatch
this.debounceExecute = async (value) => {
//if (this.totalThreads === 1) {
this.latestValue = value;
if (!pool.length) pool[0] = getThread(asyncFunction);
return new Promise((resolve, reject) => {
// If batch has expired
if (!this.nextBatch || Date.now() >= this.nextBatch) {
this.nextBatch = Date.now() + this.debounce;
if (this.batchEnds === undefined || Date.now() >= this.batchEnds) {
// This describes the end of the
// current batch of incoming executions
this.batchEnds = Date.now() + this.debounce;
}

@@ -117,4 +115,2 @@

const executeIn = this.nextBatch - (Date.now());
new Promise(() => {

@@ -124,5 +120,6 @@ setTimeout(() => {

if (this.latestValue === value || this.lastExecution === undefined) {
//console.log("latestValue - calling fn", this.latestValue);
this.lastExecution = this.execute(value).then((result) => {
//console.log(result);
// When we have a known result set it to
// the resolved value
this.lastKnownResult = result;

@@ -132,16 +129,18 @@ return result;

// Resolve the new latest value function
resolve(this.lastExecution);
} else {
//console.log("intermediate value, not calling fn");
}
// If we have an intermittent known result, resolve that
if (this.lastKnownResult !== undefined) {
//console.log("Resolving lastKnownResult", this.lastKnownResult)
resolve(Promise.resolve(this.lastKnownResult));
}
// Else lets just resolve to the currently executing
// function
resolve(this.lastExecution);
}, executeIn)
},
this.batchEnds - Date.now()) // The time at which to execute
});

@@ -151,6 +150,2 @@

// } else {
// throw Error("waitExecute requires only use of one worker");
// }
}

@@ -157,0 +152,0 @@

{
"name": "fibrelite",
"version": "1.0.0",
"version": "1.0.1",
"source": "fibrelite.js",

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

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