-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathexample.js
61 lines (49 loc) · 928 Bytes
/
example.js
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
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const mqemitter = require('.')
const mq = mqemitter()
function subscribe (topic, obj) {
mq.on(topic, callback)
obj.close = close
function callback (value, cb) {
obj.push(value)
cb()
}
function close () {
mq.removeListener(topic, callback)
}
}
class MyQueue {
push (value) {
console.log(value)
}
}
const a = new MyQueue()
const b = new MyQueue()
const c = new MyQueue()
subscribe('hello', a)
subscribe('hello', b)
subscribe('hello', c)
mq.emit({ topic: 'hello', payload: 'world' })
a.close()
b.close()
c.close()
mq.emit({ topic: 'hello', payload: 'world' })
// const listeners = new Map()
//
//
// const queues = new Map()
//
// function subscribe (topic, queue) {
// if (listeners.has(topic)) {
//
// }
//
// function callback (err) {
//
// for (var value of queues) {
// }
// }
//
// listeners.set(topic, callback)
// queues.set(topic, [queue])
// }