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

spica

Package Overview
Dependencies
Maintainers
1
Versions
804
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spica - npm Package Compare versions

Comparing version 0.0.736 to 0.0.737

6

coaggregator.test.ts

@@ -69,3 +69,3 @@ import { Coaggregator } from './coaggregator';

}),
]);
], rs => rs.reduce((a, b) => a + b));
const gen = co[Symbol.asyncIterator]();

@@ -93,6 +93,6 @@ assert.deepStrictEqual(

{
value: 4,
value: 7,
done: true
});
assert(await co === 4);
assert(await co === 7);
});

@@ -99,0 +99,0 @@

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

import { isArray } from './alias';
import { Coroutine, CoroutineOptions } from './coroutine';

@@ -7,3 +8,3 @@ import { AtomicPromise, never } from './promise';

constructor(
coroutines: readonly Coroutine<T, R, S>[],
coroutines: Iterable<Coroutine<T, R, S>>,
reducer: (results: T[]) => T = results => results[0],

@@ -13,5 +14,8 @@ opts?: CoroutineOptions,

super(async function* () {
const cs = isArray(coroutines)
? coroutines
: [...coroutines];
this.then(
result => {
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](result);

@@ -22,8 +26,8 @@ }

const rejection = AtomicPromise.reject(reason);
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](rejection);
}
});
const results: T[] = Array(coroutines.length);
for await (const { name, result } of select(coroutines)) {
const results: T[] = [];
for await (const { name, result } of select(cs)) {
assert(Number.isSafeInteger(+name));

@@ -38,3 +42,3 @@ if (result.done) {

assert(Object.keys(results).length === results.length);
assert(results.length === coroutines.length);
assert(results.length === cs.length);
results.length === 0

@@ -41,0 +45,0 @@ ? this[Coroutine.terminate](new Error(`Spica: Coaggregator: No result.`))

@@ -13,4 +13,2 @@ import { cofetch } from './cofetch';

types.push(ev.type);
if (ev.type !== 'loadend') continue;
for await (const _ of co) throw 1;
}

@@ -28,4 +26,2 @@ assert.deepStrictEqual([types[0], types.at(-1)], ['loadstart', 'loadend']);

co.cancel();
if (ev.type !== 'loadend') continue;
for await (const _ of co) throw 1;
}

@@ -32,0 +28,0 @@ assert.deepStrictEqual([...types], ['loadstart', 'loadend']);

@@ -5,15 +5,15 @@ import { isArray } from './alias';

// Must support living iterables.
export class Copropagator<T = unknown, R = T, S = unknown> extends Coroutine<T, R, S> {
constructor(
coroutines: Iterable<Coroutine<T, R, unknown>>,
coroutines: Iterable<Coroutine<T, unknown, unknown>>,
reducer: (results: T[]) => T = results => results[0],
opts?: CoroutineOptions,
) {
assert(new Set(coroutines).size === [...coroutines].length);
const cs = isArray(coroutines)
? coroutines
: [...coroutines];
super(async function* () {
this.then(
result => {
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](result);

@@ -24,7 +24,7 @@ }

const rejection = AtomicPromise.reject(reason);
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](rejection);
}
});
all(coroutines).then(
AtomicPromise.all(cs).then(
results =>

@@ -40,21 +40,1 @@ results.length === 0

}
function all<T>(sources: Iterable<PromiseLike<T>>, memory?: Map<PromiseLike<T>, T>): AtomicPromise<T[]> {
const before = isArray(sources)
? sources
: [...sources];
return AtomicPromise.all(before).then(values => {
const after = isArray(sources)
? sources
: [...sources];
const same = after.length === before.length && after.every((_, i) => after[i] === before[i]);
if (!memory && same) return values;
memory ??= new Map();
for (let i = 0; i < values.length; ++i) {
memory.set(before[i], values[i]);
}
return same
? [...memory.values()]
: all(after, memory);
});
}
{
"name": "spica",
"version": "0.0.736",
"version": "0.0.737",
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.",

@@ -60,24 +60,24 @@ "private": false,

"@types/yallist": "4.0.1",
"@typescript-eslint/parser": "^5.59.9",
"@typescript-eslint/parser": "^5.60.0",
"babel-loader": "^9.1.2",
"babel-plugin-unassert": "^3.2.0",
"bluebird": "^3.7.2",
"concurrently": "^8.1.0",
"eslint": "^8.42.0",
"concurrently": "^8.2.0",
"eslint": "^8.43.0",
"eslint-plugin-redos": "^4.4.5",
"eslint-webpack-plugin": "^4.0.1",
"glob": "^10.2.7",
"glob": "^10.3.0",
"karma": "^6.4.2",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.0",
"karma-coverage": "^2.2.1",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-power-assert": "^1.0.0",
"lru-cache": "^9.1.2",
"lru-cache": "^10.0.0",
"mocha": "^10.2.0",
"npm-check-updates": "^16.10.12",
"npm-check-updates": "^16.10.13",
"ts-loader": "^9.4.3",
"typescript": "5.1.3",
"webpack": "^5.85.1",
"webpack-cli": "^5.1.3",
"webpack": "^5.88.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.9.0",

@@ -84,0 +84,0 @@ "yallist": "^4.0.0",

@@ -69,3 +69,3 @@ import { Coaggregator } from './coaggregator';

}),
]);
], rs => rs.reduce((a, b) => a + b));
const gen = co[Symbol.asyncIterator]();

@@ -93,6 +93,6 @@ assert.deepStrictEqual(

{
value: 4,
value: 7,
done: true
});
assert(await co === 4);
assert(await co === 7);
});

@@ -99,0 +99,0 @@

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

import { isArray } from './alias';
import { Coroutine, CoroutineOptions } from './coroutine';

@@ -7,3 +8,3 @@ import { AtomicPromise, never } from './promise';

constructor(
coroutines: readonly Coroutine<T, R, S>[],
coroutines: Iterable<Coroutine<T, R, S>>,
reducer: (results: T[]) => T = results => results[0],

@@ -13,5 +14,8 @@ opts?: CoroutineOptions,

super(async function* () {
const cs = isArray(coroutines)
? coroutines
: [...coroutines];
this.then(
result => {
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](result);

@@ -22,8 +26,8 @@ }

const rejection = AtomicPromise.reject(reason);
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](rejection);
}
});
const results: T[] = Array(coroutines.length);
for await (const { name, result } of select(coroutines)) {
const results: T[] = [];
for await (const { name, result } of select(cs)) {
assert(Number.isSafeInteger(+name));

@@ -38,3 +42,3 @@ if (result.done) {

assert(Object.keys(results).length === results.length);
assert(results.length === coroutines.length);
assert(results.length === cs.length);
results.length === 0

@@ -41,0 +45,0 @@ ? this[Coroutine.terminate](new Error(`Spica: Coaggregator: No result.`))

@@ -13,4 +13,2 @@ import { cofetch } from './cofetch';

types.push(ev.type);
if (ev.type !== 'loadend') continue;
for await (const _ of co) throw 1;
}

@@ -28,4 +26,2 @@ assert.deepStrictEqual([types[0], types.at(-1)], ['loadstart', 'loadend']);

co.cancel();
if (ev.type !== 'loadend') continue;
for await (const _ of co) throw 1;
}

@@ -32,0 +28,0 @@ assert.deepStrictEqual([...types], ['loadstart', 'loadend']);

@@ -5,15 +5,15 @@ import { isArray } from './alias';

// Must support living iterables.
export class Copropagator<T = unknown, R = T, S = unknown> extends Coroutine<T, R, S> {
constructor(
coroutines: Iterable<Coroutine<T, R, unknown>>,
coroutines: Iterable<Coroutine<T, unknown, unknown>>,
reducer: (results: T[]) => T = results => results[0],
opts?: CoroutineOptions,
) {
assert(new Set(coroutines).size === [...coroutines].length);
const cs = isArray(coroutines)
? coroutines
: [...coroutines];
super(async function* () {
this.then(
result => {
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](result);

@@ -24,7 +24,7 @@ }

const rejection = AtomicPromise.reject(reason);
for (const co of coroutines) {
for (const co of cs) {
co[Coroutine.exit](rejection);
}
});
all(coroutines).then(
AtomicPromise.all(cs).then(
results =>

@@ -40,21 +40,1 @@ results.length === 0

}
function all<T>(sources: Iterable<PromiseLike<T>>, memory?: Map<PromiseLike<T>, T>): AtomicPromise<T[]> {
const before = isArray(sources)
? sources
: [...sources];
return AtomicPromise.all(before).then(values => {
const after = isArray(sources)
? sources
: [...sources];
const same = after.length === before.length && after.every((_, i) => after[i] === before[i]);
if (!memory && same) return values;
memory ??= new Map();
for (let i = 0; i < values.length; ++i) {
memory.set(before[i], values[i]);
}
return same
? [...memory.values()]
: all(after, memory);
});
}
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