Skip to content

Commit a14580b

Browse files
committed
fix: doc
1 parent a0f4ea3 commit a14580b

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,25 @@ context.set('foo', 'bar');
6464

6565
const res = await Promise.all([
6666
new Promise((resolve) => {
67-
context.fork();
68-
context.set('foo', 'tata');
67+
context.fork().set('foo', 'tata');
6968
setTimeout(() => {
7069
resolve(func());
7170
}, 400);
7271
}),
7372
new Promise((resolve) => {
74-
context.fork();
75-
context.set('foo', 'toto');
73+
context.fork().set('foo', 'toto');
7674
setTimeout(() => {
7775
resolve(func());
7876
}, 200);
7977
}),
8078
new Promise((resolve) => {
81-
context.fork();
82-
context.set('foo', 'titi');
79+
context.fork().set('foo', 'titi');
8380
setTimeout(() => {
8481
resolve(func());
8582
}, 100);
8683
}),
8784
new Promise((resolve) => {
88-
context.fork();
89-
context.set('foo', 'tutu');
85+
context.fork().set('foo', 'tutu');
9086
setTimeout(() => {
9187
resolve(func());
9288
}, 600);

src/__tests__/context.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,25 @@ describe('SimpleContext', () => {
2626

2727
const res = await Promise.all([
2828
new Promise((resolve) => {
29-
context.fork();
30-
context.set('foo', 'tata');
29+
context.fork().set('foo', 'tata');
3130
setTimeout(() => {
3231
resolve(func());
3332
}, 400);
3433
}),
3534
new Promise((resolve) => {
36-
context.fork();
37-
context.set('foo', 'toto');
35+
context.fork().set('foo', 'toto');
3836
setTimeout(() => {
3937
resolve(func());
4038
}, 200);
4139
}),
4240
new Promise((resolve) => {
43-
context.fork();
44-
context.set('foo', 'titi');
41+
context.fork().set('foo', 'titi');
4542
setTimeout(() => {
4643
resolve(func());
4744
}, 100);
4845
}),
4946
new Promise((resolve) => {
50-
context.fork();
51-
context.set('foo', 'tutu');
47+
context.fork().set('foo', 'tutu');
5248
setTimeout(() => {
5349
resolve(func());
5450
}, 600);

src/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export class SimpleContext {
3030
return this.setForkProperty<T>(key, value);
3131
}
3232

33-
public fork(): void {
33+
public fork(): SimpleContext {
3434
this.store.set(asyncHooks.executionAsyncId(), {});
35+
return this;
3536
}
3637

3738
private setForkProperty<T>(key: string, value: T): void {

0 commit comments

Comments
 (0)