Skip to content

Commit 4f763c6

Browse files
committed
fix(dispatch): remove infinite loop limit
1 parent bb5b424 commit 4f763c6

3 files changed

Lines changed: 0 additions & 27 deletions

File tree

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ mySignal.add(listener)
146146
mySignal.removeAll()
147147
```
148148

149-
## Notes
150-
151-
In order to prevent an __infinite loop__ if a signal is dispatching itself in an added listener, the maximum dispatch limit is fixed to __512__.
152-
153-
If this limit is reached, it throws an error.
154-
155149
## API
156150

157151
See [https://fm-ph.github.io/quark-signal/](https://fm-ph.github.io/quark-signal/)

src/index.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/**
2-
* @constant
3-
* @type number
4-
* @default
5-
*/
6-
const MAX_DISPATCH_NB = 512
7-
81
/**
92
* Signal class
103
*
@@ -143,10 +136,6 @@ class Signal {
143136
dispatch (...args) {
144137
this._dispatchNb++
145138

146-
if (this._dispatchNb > MAX_DISPATCH_NB) {
147-
throw new Error('Signal.dispatch() : Maximum dispatch limit reached (prevent infinite loop)')
148-
}
149-
150139
for (let i = 0; i < this._listeners.length; i++) {
151140
const listener = this._listeners[i]
152141

test/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,6 @@ test.cb('create a signal and use a custom listener context', t => {
166166
t.context.signal.dispatch()
167167
})
168168

169-
test('create a signal that dispatch itself throws an error', t => {
170-
t.context.signal.add(() => {
171-
t.context.signal.dispatch()
172-
})
173-
174-
const error = t.throws(() => t.context.signal.dispatch(), Error)
175-
176-
t.is(error.message, 'Signal.dispatch() : Maximum dispatch limit reached (prevent infinite loop)')
177-
})
178-
179169
test('create a signal with a listener that stop the propagation', t => {
180170
t.context.signal.add(() => false)
181171
t.context.signal.add(() => { })

0 commit comments

Comments
 (0)