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

comsync

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comsync - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

2

dist/index.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("sync-message"),require("comlink")):"function"==typeof define&&define.amd?define(["sync-message","comlink"],t):"object"==typeof exports?exports.comsync=t(require("sync-message"),require("comlink")):e.comsync=t(e["sync-message"],e.comlink)}(self,(function(e,t){return(()=>{"use strict";var r={272:e=>{e.exports=t},746:t=>{t.exports=e}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{o.r(i),o.d(i,{InterruptError:()=>c,NoChannelError:()=>l,TaskClient:()=>f,exposeSync:()=>p});var e,t=o(746),r=o(272),n=(e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}),s=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))},a=function(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},u=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))},c=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="InterruptError",t}return n(t,e),t}(Error),l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="NoChannelError",t}return n(t,e),t}(Error),f=function(){function e(e,t){this.workerCreator=e,this.channel=t,this.state="idle",this._messageId="",this._start()}return e.prototype.interrupt=function(e){return s(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return"idle"===this.state?[2]:(this.state="idle",e?[3,4]:this._messageId?[4,this._writeMessage({interrupted:!0})]:[3,2]);case 1:case 3:return t.sent(),[2];case 2:return this.interrupter?[4,this.interrupter()]:[3,4];case 4:return this.terminate(),this._start(),[2]}}))}))},e.prototype.runTask=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return s(this,void 0,void 0,(function(){var n,o,i=this;return a(this,(function(s){switch(s.label){case 0:if("idle"!==this.state)throw new Error("Still running a task");this.state="running",n=this,o=function(e,t){n._messageId=e,t&&(n.state="awaitingMessage")},this._interruptPromise=new Promise((function(e,t){return i.interruptRejector=t})),s.label=1;case 1:return s.trys.push([1,,3,4]),[4,Promise.race([e.apply(void 0,u([this.channel,r.proxy(o)],t,!1)),this._interruptPromise])];case 2:return[2,s.sent()];case 3:return this.state="idle",delete this._interruptPromise,delete this.interruptRejector,[7];case 4:return[2]}}))}))},e.prototype.writeMessage=function(e){return s(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:if("awaitingMessage"!==this.state)throw new Error("Not waiting for message");return this.state="running",[4,this._writeMessage({message:e})];case 1:return t.sent(),[2]}}))}))},e.prototype.terminate=function(){var e;this.state="idle",null===(e=this.interruptRejector)||void 0===e||e.call(this,new c("Worker terminated")),this.workerProxy[r.releaseProxy](),this.worker.terminate(),delete this.workerProxy,delete this.worker},e.prototype._writeMessage=function(e){return s(this,void 0,void 0,(function(){var r;return a(this,(function(n){switch(n.label){case 0:if(!(r=this._messageId))throw new Error("No messageId set");return this._messageId="",[4,(0,t.writeMessage)(this.channel,e,r)];case 1:return n.sent(),[2]}}))}))},e.prototype._start=function(){this.worker=this.workerCreator(),this.workerProxy=r.wrap(this.worker)},e}();function p(e){return function(r,n){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];function s(e,o){if(!r)throw new l;var i=(0,t.uuidv4)();n(i,e);var s=(0,t.readMessage)(r,i,o);if(s){var a=s.message;if(s.interrupted)throw new c;return a}}var a={channel:r,readMessage:function(){return s(!0)},syncSleep:function(e){e>0&&s(!1,{timeout:e})}};return e.apply(void 0,u([a],o,!1))}}})(),i})()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("sync-message"),require("comlink")):"function"==typeof define&&define.amd?define(["sync-message","comlink"],t):"object"==typeof exports?exports.comsync=t(require("sync-message"),require("comlink")):e.comsync=t(e["sync-message"],e.comlink)}(self,(function(e,t){return(()=>{"use strict";var r={272:e=>{e.exports=t},746:t=>{t.exports=e}},i={};function s(e){var t=i[e];if(void 0!==t)return t.exports;var n=i[e]={exports:{}};return r[e](n,n.exports,s),n.exports}s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{for(var r in t)s.o(t,r)&&!s.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{s.r(n),s.d(n,{InterruptError:()=>i,NoChannelError:()=>o,TaskClient:()=>a,exposeSync:()=>u});var e=s(746),t=s(272),r=function(e,t,r,i){return new(r||(r=Promise))((function(s,n){function o(e){try{u(i.next(e))}catch(e){n(e)}}function a(e){try{u(i.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}u((i=i.apply(e,t||[])).next())}))};class i extends Error{constructor(){super(...arguments),this.type="InterruptError"}}class o extends Error{constructor(){super(...arguments),this.type="NoChannelError"}}class a{constructor(e,t){this.workerCreator=e,this.channel=t,this.state="idle",this._messageId="",this._start()}interrupt(e){return r(this,void 0,void 0,(function*(){if("idle"!==this.state){if(this.state="idle",!e){if(this._messageId)return void(yield this._writeMessage({interrupted:!0}));if(this.interrupter)return void(yield this.interrupter())}this.terminate(),this._start()}}))}runTask(e,...i){return r(this,void 0,void 0,(function*(){if("idle"!==this.state)throw new Error("Still running a task");this.state="running";const r=this,s=(e,t)=>{r._messageId=e,t&&(r.state="awaitingMessage")};this._interruptPromise=new Promise(((e,t)=>this.interruptRejector=t));try{return yield Promise.race([e(this.channel,t.proxy(s),...i),this._interruptPromise])}finally{this.state="idle",delete this._interruptPromise,delete this.interruptRejector}}))}writeMessage(e){return r(this,void 0,void 0,(function*(){if("awaitingMessage"!==this.state)throw new Error("Not waiting for message");this.state="running",yield this._writeMessage({message:e})}))}terminate(){var e;this.state="idle",null===(e=this.interruptRejector)||void 0===e||e.call(this,new i("Worker terminated")),this.workerProxy[t.releaseProxy](),this.worker.terminate(),delete this.workerProxy,delete this.worker}_writeMessage(t){return r(this,void 0,void 0,(function*(){const{_messageId:r}=this;if(!r)throw new Error("No messageId set");this._messageId="",yield(0,e.writeMessage)(this.channel,t,r)}))}_start(){this.worker=this.workerCreator(),this.workerProxy=t.wrap(this.worker)}}function u(t){return function(r,s,...n){function a(t,n){if(!r)throw new o;const a=(0,e.uuidv4)();s(a,t);const u=(0,e.readMessage)(r,a,n);if(u){const{message:e,interrupted:t}=u;if(t)throw new i;return e}}return t({channel:r,readMessage:()=>a(!0),syncSleep(e){e>0&&a(!1,{timeout:e})}},...n)}}})(),n})()}));
//# sourceMappingURL=index.js.map
{
"name": "comsync",
"version": "0.0.4",
"version": "0.0.5",
"private": false,

@@ -5,0 +5,0 @@ "repository": {

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