| 12345678910111213141516171819202122232425262728293031323334 |
- const eventBus = require('../src/service/EventBus').default
- class TestJob {
- constructor(name) {
- this.name = name
- this.interval = setInterval(() => {
- console.log(`${this.name} is running`)
- }, 1000);
- this.subscription = eventBus.subscribe('pause', arg => {
- this.onPause(arg)
- })
- }
- onPause(i) {
- if (this.name === i) {
- clearInterval(this.interval)
- this.subscription.unsubscribe()
- console.log(`${this.name} pasued`)
- }
- }
- }
- for (let i = 0; i < 5; i++) {
- let job = new TestJob(`job ${i}`)
- }
- setTimeout(() => {
- console.log('pause job3')
- eventBus.publish('pause', 'job 3')
- }, 4000)
- setTimeout(() => {
- console.log('pause job3')
- eventBus.publish('pause', 'job 3')
- }, 10000)
|