Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 8296b76

Browse files
committed
fix Non-blocking
1 parent 0549ccb commit 8296b76

13 files changed

+26
-103
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ like [co](https://github.com/tj/co), or [redux-saga](https://redux-saga.js.org)
1010
- [API](https://github.com/dineug/go/tree/main/packages/go#api)
1111
- [go](https://github.com/dineug/go/tree/main/packages/go#go)
1212
- [all](https://github.com/dineug/go/tree/main/packages/go#all)
13-
- [call](https://github.com/dineug/go/tree/main/packages/go#call)
1413
- [cancel](https://github.com/dineug/go/tree/main/packages/go#cancel)
1514
- [debounce](https://github.com/dineug/go/tree/main/packages/go#debounce)
1615
- [delay](https://github.com/dineug/go/tree/main/packages/go#delay)
1716
- [flush](https://github.com/dineug/go/tree/main/packages/go#flush)
18-
- [fork](https://github.com/dineug/go/tree/main/packages/go#fork)
1917
- [kill](https://github.com/dineug/go/tree/main/packages/go#kill)
2018
- [put](https://github.com/dineug/go/tree/main/packages/go#put)
2119
- [race](https://github.com/dineug/go/tree/main/packages/go#race)

packages/go/README.md

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ like [co](https://github.com/tj/co), or [redux-saga](https://redux-saga.js.org)
1010
- [API](#api)
1111
- [go](#go)
1212
- [all](#all)
13-
- [call](#call)
1413
- [cancel](#cancel)
1514
- [debounce](#debounce)
1615
- [delay](#delay)
1716
- [flush](#flush)
18-
- [fork](#fork)
1917
- [kill](#kill)
2018
- [put](#put)
2119
- [race](#race)
@@ -36,12 +34,10 @@ npm install @dineug/go
3634
```ts
3735
import {
3836
all,
39-
call,
4037
channel,
4138
CO,
4239
delay,
4340
flush,
44-
fork,
4541
go,
4642
put,
4743
race,
@@ -52,15 +48,15 @@ const ch = channel();
5248

5349
const foo: CO = function* () {
5450
const value = yield take(ch);
55-
const value2 = yield call(v => v, value);
51+
const value2 = yield go(v => v, value);
5652

57-
yield fork(function* () {
53+
go(function* () {
5854
const value = yield take(ch);
5955
});
6056

6157
const values = yield all([
62-
call(() => 1),
63-
fork(() => 2),
58+
go(() => 1),
59+
go(() => 2),
6460
Promise.resolve(3),
6561
Promise.resolve(4),
6662
5,
@@ -154,8 +150,7 @@ Same as Promise.all
154150

155151
```js
156152
all([
157-
call(() => 1),
158-
fork(() => 2),
153+
go(() => 1),
159154
Promise.resolve(3),
160155
Promise.resolve(4),
161156
5,
@@ -175,22 +170,6 @@ const all = values =>
175170
});
176171
```
177172

178-
### call
179-
180-
Same as go
181-
182-
#### Example
183-
184-
```js
185-
call(function* () {});
186-
```
187-
188-
#### low-level operator
189-
190-
```js
191-
const call = go;
192-
```
193-
194173
### cancel
195174

196175
Cancel the promise
@@ -241,7 +220,7 @@ debounce(ch, function* () {}, 1000);
241220
#### low-level operator
242221

243222
```js
244-
const debounce = (channel, callback, ms) => {
223+
const debounce = (channel, callback, ms) =>
245224
go(function* () {
246225
let timerId = -1;
247226

@@ -252,7 +231,6 @@ const debounce = (channel, callback, ms) => {
252231
timerId = window.setTimeout(go, ms, callback, value);
253232
}
254233
});
255-
};
256234
```
257235

258236
### delay
@@ -289,24 +267,6 @@ const flush = channel =>
289267
new Promise((resolve, reject) => channel.flush(resolve, reject));
290268
```
291269

292-
### fork
293-
294-
#### Example
295-
296-
```js
297-
go(function* () {
298-
yield fork(function* () {});
299-
});
300-
```
301-
302-
#### low-level operator
303-
304-
```js
305-
const fork = (callback, ...args) => {
306-
go(callback, ...args);
307-
};
308-
```
309-
310270
### kill
311271

312272
Exit All
@@ -315,8 +275,8 @@ Exit All
315275

316276
```js
317277
go(function* () {
318-
yield call(function* () {
319-
yield call(function* () {
278+
yield go(function* () {
279+
yield go(function* () {
320280
yield kill();
321281
});
322282
});
@@ -426,14 +386,13 @@ takeEvery(ch, function* () {});
426386
#### low-level operator
427387

428388
```js
429-
const takeEvery = (channel, callback) => {
389+
const takeEvery = (channel, callback) =>
430390
go(function* () {
431391
while (true) {
432392
const value = yield take(channel);
433393
go(callback, value);
434394
}
435395
});
436-
};
437396
```
438397

439398
### takeLatest
@@ -447,7 +406,7 @@ takeLatest(ch, function* () {});
447406
#### low-level operator
448407

449408
```js
450-
const takeLatest = (channel, callback) => {
409+
const takeLatest = (channel, callback) =>
451410
go(function* () {
452411
let lastTask;
453412

@@ -457,7 +416,6 @@ const takeLatest = (channel, callback) => {
457416
lastTask = go(callback, value);
458417
}
459418
});
460-
};
461419
```
462420

463421
### takeLeading
@@ -471,7 +429,7 @@ takeLeading(ch, function* () {});
471429
#### low-level operator
472430

473431
```js
474-
const takeLeading = (channel, callback) => {
432+
const takeLeading = (channel, callback) =>
475433
go(function* () {
476434
let executable = true;
477435

@@ -486,7 +444,6 @@ const takeLeading = (channel, callback) => {
486444
}
487445
}
488446
});
489-
};
490447
```
491448

492449
### throttle
@@ -510,7 +467,7 @@ const defaultConfig: Required<ThrottleConfig> = {
510467
trailing: false,
511468
};
512469

513-
const throttle = (channel, callback, ms, config) => {
470+
const throttle = (channel, callback, ms, config) =>
514471
go(function* () {
515472
const options = Object.assign({}, defaultConfig, {
516473
...config,
@@ -541,5 +498,4 @@ const throttle = (channel, callback, ms, config) => {
541498
}, ms);
542499
}
543500
});
544-
};
545501
```

packages/go/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dineug/go",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "Promise Extension Library",
55
"main": "dist/go.js",
66
"module": "dist/go.esm.js",

packages/go/src/index.dev.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
import {
2-
all,
3-
call,
4-
channel,
5-
CO,
6-
delay,
7-
flush,
8-
fork,
9-
go,
10-
put,
11-
race,
12-
take,
13-
} from '@/index';
1+
import { all, channel, CO, delay, flush, go, put, race, take } from '@/index';
142

153
const inputChannel = channel<number>();
164
const outputChannel = channel<number>();
@@ -19,18 +7,18 @@ const foo: CO = function* () {
197
console.log('start');
208
const value = yield take(inputChannel);
219
console.log('take:value', value);
22-
const value2 = yield call((v: any) => v, value);
10+
const value2 = yield go((v: any) => v, value);
2311
console.log('call:value', value2);
2412
yield put(outputChannel, 1234);
2513

26-
yield fork(function* () {
14+
go(function* () {
2715
const value = yield take(inputChannel);
2816
console.log('fork:take:value', value);
2917
});
3018

3119
const values = yield all([
32-
call(() => 1),
33-
fork(() => 2),
20+
go(() => 1),
21+
go(() => 2),
3422
Promise.resolve(3),
3523
Promise.resolve(4),
3624
5,

packages/go/src/operators/call.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/go/src/operators/debounce.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const debounce = <
99
channel: Channel<T>,
1010
callback: F,
1111
ms: number
12-
) => {
12+
) =>
1313
go(function* () {
1414
let timerId = -1;
1515

@@ -20,4 +20,3 @@ export const debounce = <
2020
timerId = window.setTimeout(go, ms, callback, value);
2121
}
2222
});
23-
};

packages/go/src/operators/fork.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/go/src/operators/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
export * from '@/operators/all';
2-
export * from '@/operators/call';
32
export * from '@/operators/cancel';
43
export * from '@/operators/debounce';
54
export * from '@/operators/delay';
65
export * from '@/operators/flush';
7-
export * from '@/operators/fork';
86
export * from '@/operators/kill';
97
export * from '@/operators/put';
108
export * from '@/operators/race';

packages/go/src/operators/take.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Channel } from '@/channel';
2-
import { type PromiseWithCancel, go } from '@/go';
2+
import { go, type PromiseWithCancel } from '@/go';
33

44
export const take = <T = any>(channel: Channel<T>) =>
55
go(function* () {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import { type TakeCallback, Channel } from '@/channel';
1+
import { Channel, type TakeCallback } from '@/channel';
22
import { go } from '@/go';
33
import { take } from '@/operators/take';
44

55
export const takeEvery = <T = any, F extends TakeCallback<T> = TakeCallback<T>>(
66
channel: Channel<T>,
77
callback: F
8-
) => {
8+
) =>
99
go(function* () {
1010
while (true) {
1111
const value = yield take(channel);
1212
// @ts-ignore
1313
go(callback, value);
1414
}
1515
});
16-
};

packages/go/src/operators/takeLatest.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Channel } from '@/channel';
2-
import { type PromiseWithCancel, go } from '@/go';
2+
import { go, type PromiseWithCancel } from '@/go';
33
import { cancel } from '@/operators/cancel';
44
import { take } from '@/operators/take';
55

@@ -9,7 +9,7 @@ export const takeLatest = <
99
>(
1010
channel: Channel<T>,
1111
callback: F
12-
) => {
12+
) =>
1313
go(function* () {
1414
let lastTask: PromiseWithCancel | undefined;
1515

@@ -20,4 +20,3 @@ export const takeLatest = <
2020
lastTask = go(callback, value);
2121
}
2222
});
23-
};

packages/go/src/operators/takeLeading.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const takeLeading = <
88
>(
99
channel: Channel<T>,
1010
callback: F
11-
) => {
11+
) =>
1212
go(function* () {
1313
let executable = true;
1414

@@ -24,4 +24,3 @@ export const takeLeading = <
2424
}
2525
}
2626
});
27-
};

packages/go/src/operators/throttle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const throttle = <
2020
callback: F,
2121
ms: number,
2222
config?: ThrottleConfig
23-
) => {
23+
) =>
2424
go(function* () {
2525
const options = Object.assign({}, defaultConfig, {
2626
...config,
@@ -53,4 +53,3 @@ export const throttle = <
5353
}, ms);
5454
}
5555
});
56-
};

0 commit comments

Comments
 (0)