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

Commit 79c1b4c

Browse files
authored
Merge branch 'master' into master
2 parents fb6d18a + f719574 commit 79c1b4c

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) {
@@ -61,7 +64,7 @@ function SearchPager (opts) {
6164
emitter.on('error', this._onError.bind(this))
6265
this.childEmitter = emitter
6366
}
64-
util.inherits(SearchPager, EventEmitter)
67+
util.inherits(SearchPager, CorkedEmitter)
6568
module.exports = SearchPager
6669

6770
/**
@@ -144,8 +147,7 @@ SearchPager.prototype._nextPage = function _nextPage (cookie) {
144147
}
145148
}))
146149

147-
this.emit('search', controls, this.childEmitter,
148-
this._sendCallback.bind(this))
150+
this.sendRequest(controls, this.childEmitter, this._sendCallback.bind(this))
149151
}
150152

151153
/**

test/client.test.js

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

914+
tap.test('paged - search with delayed event listener binding', function (t) {
915+
t.context.client.search('cn=paged', { filter: '(objectclass=*)', paged: true }, function (err, res) {
916+
t.error(err)
917+
setTimeout(() => {
918+
let gotEntry = 0
919+
res.on('searchEntry', function () {
920+
gotEntry++
921+
})
922+
res.on('error', function (err) {
923+
t.fail(err)
924+
})
925+
res.on('end', function () {
926+
t.equal(gotEntry, 1000)
927+
t.end()
928+
})
929+
}, 100)
930+
})
931+
})
932+
914933
t.end()
915934
})
916935

0 commit comments

Comments
 (0)