Socket
Socket
Sign inDemoInstall

effection

Package Overview
Dependencies
Maintainers
1
Versions
299
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

effection - npm Package Compare versions

Comparing version 0.4.0-bbebdf3 to 0.4.0-beda95a

dist-src/pattern-match.js

124

dist-node/index.js

@@ -5,2 +5,4 @@ 'use strict';

var events = require('events');
/**

@@ -96,4 +98,3 @@ * Create an execution controller that resumes after the specified

}
class Fork {
class Fork extends events.EventEmitter {
get isUnstarted() {

@@ -159,2 +160,3 @@ return this.state === 'unstarted';

constructor(operation, parent, sync) {
super();
this.id = Fork.ids++;

@@ -165,2 +167,3 @@ this.operation = toGeneratorFunction(operation);

this.children = new Set();
this.mailbox = [];
this.state = 'unstarted';

@@ -350,2 +353,13 @@ this.exitPrevious = noop;

send(message) {
this.mailbox.push(message);
this.emit("message", message);
}
sendParent(message) {
if (this.parent) {
this.parent.send(message);
}
}
get root() {

@@ -393,4 +407,110 @@ if (this.parent) {

function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
return;
}
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
function any(type) {
if (type === "array") {
return function anyMatcher(value) {
return Array.isArray(value);
};
} else if (type) {
return function anyMatcher(value) {
return typeof value === type;
};
} else {
return function anyMatcher() {
return true;
};
}
}
function patternMatch(match) {
return function matcher(target) {
if (match === undefined) {
return true;
} else if (Array.isArray(match)) {
return match.every((value, index) => patternMatch(value)(target[index]));
} else if (typeof match === "object") {
return Object.entries(match).every(([key, value]) => patternMatch(value)(target[key]));
} else if (typeof match === "function") {
return match(target);
} else {
return match === target;
}
};
}
function receive(target, match) {
if (target && !(target instanceof Fork)) {
match = target;
target = undefined;
}
return execution => {
if (!target) {
target = execution;
}
function scanMailbox() {
let index = target.mailbox.findIndex(message => patternMatch(match)(message));
if (index >= 0) {
let _target$mailbox$splic = target.mailbox.splice(index, 1),
_target$mailbox$splic2 = _slicedToArray(_target$mailbox$splic, 1),
message = _target$mailbox$splic2[0];
execution.resume(message);
}
}
scanMailbox();
target.on("message", scanMailbox);
return () => {
target.off("message", scanMailbox);
};
};
}
exports.any = any;
exports.fork = fork;
exports.promiseOf = promiseOf;
exports.receive = receive;
exports.timeout = timeout;

@@ -6,4 +6,4 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import { isGenerator, isGeneratorFunction, toGeneratorFunction } from "./generator-function.js";
class Fork {
import { EventEmitter } from 'events';
export class Fork extends EventEmitter {
get isUnstarted() {

@@ -48,2 +48,3 @@ return this.state === 'unstarted';

constructor(operation, parent, sync) {
super();
this.id = Fork.ids++;

@@ -54,2 +55,3 @@ this.operation = toGeneratorFunction(operation);

this.children = new Set();
this.mailbox = [];
this.state = 'unstarted';

@@ -239,2 +241,13 @@ this.exitPrevious = noop;

send(message) {
this.mailbox.push(message);
this.emit("message", message);
}
sendParent(message) {
if (this.parent) {
this.parent.send(message);
}
}
get root() {

@@ -241,0 +254,0 @@ if (this.parent) {

4

dist-src/index.js
export { timeout } from "./timeout.js";
export { fork } from "./fork.js";
export { promiseOf } from "./promise-of.js";
export { promiseOf } from "./promise-of.js";
export { receive } from "./receive.js";
export { any } from "./pattern-match.js";

@@ -0,1 +1,3 @@

import { EventEmitter } from 'events';
/**

@@ -96,4 +98,3 @@ * Create an execution controller that resumes after the specified

}
class Fork {
class Fork extends EventEmitter {
get isUnstarted() {

@@ -138,2 +139,3 @@ return this.state === 'unstarted';

constructor(operation, parent, sync) {
super();
this.id = Fork.ids++;

@@ -144,2 +146,3 @@ this.operation = toGeneratorFunction(operation);

this.children = new Set();
this.mailbox = [];
this.state = 'unstarted';

@@ -302,2 +305,13 @@ this.exitPrevious = noop;

send(message) {
this.mailbox.push(message);
this.emit("message", message);
}
sendParent(message) {
if (this.parent) {
this.parent.send(message);
}
}
get root() {

@@ -347,2 +361,112 @@ if (this.parent) {

export { fork, promiseOf, timeout };
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
return;
}
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
function any(type) {
if (type === "array") {
return function anyMatcher(value) {
return Array.isArray(value);
};
} else if (type) {
return function anyMatcher(value) {
return typeof value === type;
};
} else {
return function anyMatcher() {
return true;
};
}
}
function patternMatch(match) {
return function matcher(target) {
if (match === undefined) {
return true;
} else if (Array.isArray(match)) {
return match.every((value, index) => patternMatch(value)(target[index]));
} else if (typeof match === "object") {
return Object.entries(match).every((_ref) => {
let _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return patternMatch(value)(target[key]);
});
} else if (typeof match === "function") {
return match(target);
} else {
return match === target;
}
};
}
function receive(target, match) {
if (target && !(target instanceof Fork)) {
match = target;
target = undefined;
}
return execution => {
if (!target) {
target = execution;
}
function scanMailbox() {
let index = target.mailbox.findIndex(message => patternMatch(match)(message));
if (index >= 0) {
let _target$mailbox$splic = target.mailbox.splice(index, 1),
_target$mailbox$splic2 = _slicedToArray(_target$mailbox$splic, 1),
message = _target$mailbox$splic2[0];
execution.resume(message);
}
}
scanMailbox();
target.on("message", scanMailbox);
return () => {
target.off("message", scanMailbox);
};
};
}
export { any, fork, promiseOf, receive, timeout };
declare module "effection" {
type PredicateFn = (value: any) => boolean;
type AnyTypeName = "undefined" | "object" | "boolean" | "number" | "bigint" | "string" | "symbol" | "function" | "array"
type PatternMatchObject = { [key: string]: PatternMatchOptions };
type Primitive = string | boolean | number | bigint | symbol | null | undefined;
export type PatternMatchOptions = Primitive | PatternMatchObject | PatternMatchOptions[] | PredicateFn
export type Operation = SequenceFn | Sequence | Promise<any> | Controller | Execution<any> | undefined;

@@ -13,2 +19,4 @@ export type SequenceFn = (this: Execution) => Sequence;

halt(reason?: any): void;
send(message: any): void;
sendParent(message: any): void;
}

@@ -18,3 +26,11 @@

export function receive(): Controller;
export function receive(fork: Execution<any>): Controller;
export function receive(match: PatternMatchOptions): Controller;
export function receive(fork: Execution<any>, match: PatternMatchOptions): Controller;
export function any(): PredicateFn;
export function any(type: AnyTypeName): PredicateFn;
export function timeout(durationMillis: number): Operation;
}
{
"name": "effection",
"description": "Effortlessly composable structured concurrency primitive for JavaScript",
"version": "0.4.0-bbebdf3",
"version": "0.4.0-beda95a",
"license": "MIT",

@@ -6,0 +6,0 @@ "files": [

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