Skip to content

Commit

Permalink
fix(dispatch): remove infinite loop limit
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienMotte committed Apr 10, 2017
1 parent bb5b424 commit 4f763c6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 27 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ mySignal.add(listener)
mySignal.removeAll()
```

## Notes

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__.

If this limit is reached, it throws an error.

## API

See [https://fm-ph.github.io/quark-signal/](https://fm-ph.github.io/quark-signal/)
Expand Down
11 changes: 0 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/**
* @constant
* @type number
* @default
*/
const MAX_DISPATCH_NB = 512

/**
* Signal class
*
Expand Down Expand Up @@ -143,10 +136,6 @@ class Signal {
dispatch (...args) {
this._dispatchNb++

if (this._dispatchNb > MAX_DISPATCH_NB) {
throw new Error('Signal.dispatch() : Maximum dispatch limit reached (prevent infinite loop)')
}

for (let i = 0; i < this._listeners.length; i++) {
const listener = this._listeners[i]

Expand Down
10 changes: 0 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,6 @@ test.cb('create a signal and use a custom listener context', t => {
t.context.signal.dispatch()
})

test('create a signal that dispatch itself throws an error', t => {
t.context.signal.add(() => {
t.context.signal.dispatch()
})

const error = t.throws(() => t.context.signal.dispatch(), Error)

t.is(error.message, 'Signal.dispatch() : Maximum dispatch limit reached (prevent infinite loop)')
})

test('create a signal with a listener that stop the propagation', t => {
t.context.signal.add(() => false)
t.context.signal.add(() => { })
Expand Down

0 comments on commit 4f763c6

Please sign in to comment.