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

Commit f719574

Browse files
authored
Merge pull request #723 from seewer/fix-paged-concurrent
2 parents 010b472 + 137590d commit f719574

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

lib/client/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,9 @@ Client.prototype.search = function search (base,
630630
callback: callback,
631631
controls: controls,
632632
pageSize: size,
633-
pagePause: pageOpts.pagePause
633+
pagePause: pageOpts.pagePause,
634+
sendRequest: sendRequest
634635
})
635-
pager.on('search', sendRequest)
636636
pager.begin()
637637
} else {
638638
sendRequest(controls, new CorkedEmitter(), callback)

lib/client/search_pager.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const assert = require('assert-plus')
1010
// var Protocol = require('../protocol')
1111
const PagedControl = require('../controls/paged_results_control.js')
1212

13+
const CorkedEmitter = require('../corked_emitter.js')
14+
1315
/// --- API
1416

1517
/**
@@ -29,19 +31,20 @@ const PagedControl = require('../controls/paged_results_control.js')
2931
* will be emitted (and 'end' will not be). By listening to
3032
* 'pageError', a successful search that lacks paging will be
3133
* able to emit 'end'.
32-
* 3. search - Emitted as an internal event to trigger another client search.
3334
*/
3435
function SearchPager (opts) {
3536
assert.object(opts)
3637
assert.func(opts.callback)
3738
assert.number(opts.pageSize)
39+
assert.func(opts.sendRequest)
3840

39-
EventEmitter.call(this, {})
41+
CorkedEmitter.call(this, {})
4042

4143
this.callback = opts.callback
4244
this.controls = opts.controls
4345
this.pageSize = opts.pageSize
4446
this.pagePause = opts.pagePause
47+
this.sendRequest = opts.sendRequest
4548

4649
this.controls.forEach(function (control) {
4750
if (control.type === PagedControl.OID) {
@@ -60,7 +63,7 @@ function SearchPager (opts) {
6063
emitter.on('error', this._onError.bind(this))
6164
this.childEmitter = emitter
6265
}
63-
util.inherits(SearchPager, EventEmitter)
66+
util.inherits(SearchPager, CorkedEmitter)
6467
module.exports = SearchPager
6568

6669
/**
@@ -143,8 +146,7 @@ SearchPager.prototype._nextPage = function _nextPage (cookie) {
143146
}
144147
}))
145148

146-
this.emit('search', controls, this.childEmitter,
147-
this._sendCallback.bind(this))
149+
this.sendRequest(controls, this.childEmitter, this._sendCallback.bind(this))
148150
}
149151

150152
/**

test/client.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,25 @@ tap.test('search paged', { timeout: 10000 }, function (t) {
899899
})
900900
})
901901

902+
tap.test('paged - search with delayed event listener binding', function (t) {
903+
t.context.client.search('cn=paged', { filter: '(objectclass=*)', paged: true }, function (err, res) {
904+
t.error(err)
905+
setTimeout(() => {
906+
let gotEntry = 0
907+
res.on('searchEntry', function () {
908+
gotEntry++
909+
})
910+
res.on('error', function (err) {
911+
t.fail(err)
912+
})
913+
res.on('end', function () {
914+
t.equal(gotEntry, 1000)
915+
t.end()
916+
})
917+
}, 100)
918+
})
919+
})
920+
902921
t.end()
903922
})
904923

0 commit comments

Comments
 (0)