-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtopicpool.js
More file actions
36 lines (29 loc) · 754 Bytes
/
topicpool.js
File metadata and controls
36 lines (29 loc) · 754 Bytes
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
var logger = require('./logger').logger;
// opts:
// sources: The sources for the topics in fallback order.
function createTopicPool(opts) {
function getTopic(done) {
var sourceIndex = 0;
function checkTopic(error, topic) {
if (error) {
logger.error(error);
sourceIndex += 1;
if (sourceIndex < opts.sources.length) {
getTopicFromSource(opts.sources[sourceIndex], done);
} else {
done(error);
}
} else {
done(error, topic);
}
}
getTopicFromSource(opts.sources[sourceIndex], checkTopic);
}
function getTopicFromSource(source, done) {
source.getTopic(done);
}
return {
getTopic: getTopic
};
}
module.exports = createTopicPool;