close.js
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const Aspect = require('./operation').Aspect;
const defineAspects = require('./operation').defineAspects;
const OperationBase = require('./operation').OperationBase;
const NativeTopology = require('../topologies/native_topology');
class CloseOperation extends OperationBase {
constructor(client, force) {
super();
this.client = client;
this.force = force;
}
execute(callback) {
const client = this.client;
const force = this.force;
const completeClose = err => {
client.emit('close', client);
if (!(client.topology instanceof NativeTopology)) {
for (const item of client.s.dbCache) {
item[1].emit('close', client);
}
}
client.removeAllListeners('close');
callback(err, null);
};
if (client.topology == null) {
completeClose();
return;
}
client.topology.close(force, err => {
const autoEncrypter = client.topology.s.options.autoEncrypter;
if (!autoEncrypter) {
completeClose(err);
return;
}
autoEncrypter.teardown(force, err2 => completeClose(err || err2));
});
}
}
defineAspects(CloseOperation, [Aspect.SKIP_SESSION]);
module.exports = CloseOperation;