-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
156 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const BENCH_SIGNALS = 10 | ||
export const BENCH_LISTENERS_PER_SIG = 10 | ||
export const BENCH_SIGNALS = 1 | ||
export const BENCH_LISTENERS_PER_SIG = 500 | ||
export const BENCH_EMITS_PER_SIG = 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { execute } from 'test-a-bit' | ||
import Signal from '../src/signal.js' | ||
|
||
execute('extracted all', async (success, fail) => { | ||
const sig = new Signal() | ||
|
||
let calls = 0 | ||
|
||
const emit = sig.extractEmit() | ||
const on = sig.extractOn() | ||
const once = sig.extractOnce() | ||
|
||
on(() => calls++) | ||
once(() => calls++) | ||
|
||
emit() | ||
emit() | ||
emit() | ||
|
||
calls === 4 | ||
? success('sugar fired 4 times') | ||
: fail('sugar fired ' + calls + ' times instead of 4') | ||
|
||
fail('no signal') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { execute } from 'test-a-bit' | ||
import Signal from '../src/signal.js' | ||
|
||
execute('extracted .emit()', async (success, fail) => { | ||
const sig = new Signal() | ||
|
||
let calls = 0 | ||
|
||
const emit = sig.extractEmit() | ||
|
||
sig.on(() => calls++) | ||
|
||
emit() | ||
emit() | ||
emit() | ||
|
||
calls === 3 | ||
? success('sugar fired 3 times') | ||
: fail('sugar fired ' + calls + ' times instead of 3') | ||
|
||
fail('no signal') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { execute } from 'test-a-bit' | ||
import Signal from '../src/signal.js' | ||
|
||
execute('extracted .once()', async (success, fail) => { | ||
const sig = new Signal() | ||
|
||
let calls = 0 | ||
|
||
const sugared = sig.extractOnce() | ||
|
||
sugared(() => calls++) | ||
|
||
sig.emit() | ||
sig.emit() | ||
sig.emit() | ||
|
||
calls === 1 | ||
? success('sugar fired once') | ||
: fail('sugar fired ' + calls + ' times instead of 1') | ||
|
||
fail('no signal') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { execute } from 'test-a-bit' | ||
import Signal from '../src/signal.js' | ||
|
||
execute(`don't wait 200ms`, async (success, fail) => { | ||
const sig = new Signal() | ||
|
||
setTimeout(() => sig.emit(), 1000) | ||
|
||
try { | ||
await sig.wait(200) | ||
fail(`.wait() won't throw err`) | ||
} catch (err) { | ||
success(`right, wait can't wait`) | ||
} | ||
|
||
fail('no signal') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { execute } from 'test-a-bit' | ||
import Signal from '../src/signal.js' | ||
|
||
execute('try wait 200ms', async (success, fail) => { | ||
const sig = new Signal() | ||
|
||
setTimeout(() => sig.emit(), 200) | ||
|
||
try { | ||
await sig.wait() | ||
success('.wait() works') | ||
} catch (err) { | ||
fail('oh, .wait() failed') | ||
} | ||
|
||
fail('no signal') | ||
}) |