🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

asygen

Package Overview
Dependencies
Maintainers
1
Versions
408
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asygen - npm Package Compare versions

Comparing version

to
0.0.2

6

build/defer.d.ts

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

export declare enum State {
export declare enum Status {
PENDING = "pending",

@@ -12,7 +12,7 @@ RESOLVED = "resolved",

private _reject?;
private _state;
private _status;
constructor();
get [Symbol.toStringTag](): string;
get promise(): Promise<T>;
get state(): State;
get status(): Status;
resolve(value: T): this;

@@ -19,0 +19,0 @@ reject(error: E): this;

@@ -1,7 +0,7 @@

export let State;
(function(State) {
State["PENDING"] = 'pending';
State["RESOLVED"] = 'resolved';
State["REJECTED"] = 'rejected';
})(State || (State = {}));
export let Status;
(function(Status) {
Status["PENDING"] = 'pending';
Status["RESOLVED"] = 'resolved';
Status["REJECTED"] = 'rejected';
})(Status || (Status = {}));
const counter = [

@@ -24,13 +24,7 @@ 0,

_reject;
_state = State.PENDING;
_status = Status.PENDING;
constructor(){
this._promise = new Promise((resolve, reject)=>{
this._resolve = (value)=>{
this._state = State.RESOLVED;
resolve(value);
};
this._reject = (error)=>{
this._state = State.REJECTED;
reject(error);
};
this._resolve = resolve;
this._reject = reject;
});

@@ -41,3 +35,3 @@ this.resolve = this.resolve.bind(this);

get [Symbol.toStringTag]() {
return `Deffer ${this.txts} ${this._state}`;
return `Deferred ${this.txts} ${this._status}`;
}

@@ -47,8 +41,9 @@ get promise() {

}
get state() {
return this._state;
get status() {
return this._status;
}
resolve(value) {
if (this._state === State.PENDING) {
this._resolve && this._resolve(value);
if (this._status === Status.PENDING) {
this._status = Status.RESOLVED;
this._resolve(value);
}

@@ -58,4 +53,5 @@ return this;

reject(error) {
if (this._state === State.PENDING) {
this._reject && this._reject(error);
if (this._status === Status.PENDING) {
this._status = Status.REJECTED;
this._reject(error);
}

@@ -62,0 +58,0 @@ return this;

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

interface TaskCallback<T> {
export interface TaskCallback<T> {
(value: T): Promise<T>;

@@ -8,2 +8,1 @@ }

export declare const generatorify: <T, R = unknown>(task: Task<T, R>) => AsyncIterable<T>;
export {};

@@ -9,8 +9,13 @@ import { defer } from "./defer.js";

const prev = dPoll.push(next) - 2;
dPoll[prev].resolve({
const prevDeferred = dPoll[prev];
prevDeferred.resolve({
value,
done: false
});
return dPoll[prev].promise.then((v)=>v.value);
return prevDeferred.promise.then((v)=>v.value);
})).then(async (value)=>{
dPoll[dPoll.length - 1].resolve({
value,
done: true
});
await Promise.all(dPoll.map((d)=>d.promise));

@@ -27,4 +32,4 @@ return {

const current = dPoll[0];
current?.promise?.then(()=>dPoll.shift());
return current?.promise;
current.promise.then(()=>dPoll.shift());
return current.promise;
}

@@ -31,0 +36,0 @@ };

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

export { defer, Deferred, State } from './defer';
export { generatorify } from './generatorify';
export * from './defer';
export * from './generatorify';

@@ -1,4 +0,4 @@

export { defer, Deferred, State } from "./defer.js";
export { generatorify } from "./generatorify.js";
export * from "./defer.js";
export * from "./generatorify.js";
//# sourceMappingURL=index.js.map
{
"name": "asygen",
"version": "0.0.1",
"version": "0.0.2",
"description": "0-Deps, simple and fast async generator library for browser and NodeJS",

@@ -20,3 +20,3 @@ "type": "module",

"engines": {
"node": ">=15"
"node": ">=16"
},

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

@@ -15,4 +15,6 @@ # Asygen

#### Create deferred token
```typescript
import { defer, generatorify } from 'asygen';
import { defer } from 'asygen';

@@ -28,5 +30,16 @@ const result = defer();

console.log(result.status); // resolved or rejected
```
// easy way to turn your events into asyncGenerator
for await (const data of generatorify(send => process.on('data', send))) {
#### Convert events to asyncGenerator
```typescript
import { once } from 'node:events';
import { defer, Task } from 'asygen';
// send data from the event until process exit
const task: Task = async (send) => {
process.on('data', send);
await once(process, 'exit');
};
for await (const data of generatorify(task)) {
// handle data

@@ -50,4 +63,4 @@ }

[codeclimate-url]: https://codeclimate.com/github/3axap4eHko/asygen/maintainability
[codeclimate-image]: https://api.codeclimate.com/v1/badges/0ba20f27f6db2b0fec8c/maintainability
[codeclimate-image]: https://api.codeclimate.com/v1/badges/0f24a357154bada2a37f/maintainability
[snyk-url]: https://snyk.io/test/npm/asygen/latest
[snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/3axap4eHko/asygen.svg?maxAge=43200

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

export { defer, Deferred, State } from './defer';
export { generatorify } from './generatorify';
export * from './defer';
export * from './generatorify';

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

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

Sorry, the diff of this file is not supported yet