All files / src/core stream.js

100% Statements 8/8
100% Branches 2/2
100% Functions 3/3
100% Lines 8/8
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        47x 47x         24x   24x   24x   24x       47x 24x            
import EventEmitter from 'events';
 
class Stream extends EventEmitter {
  constructor() {
    super();
    this.cache = [];
  }
 
  start() {
    // Save start date for stream
    this.startDate = new Date();
    // Stop the old stream if there is one
    this.stop();
    // Call a first request
    this.makeRequest();
    // Start setInterval and store id
    this.intervalId = setInterval(this.makeRequest.bind(this), this.interval);
  }
 
  stop() {
    if (this.intervalId) {
      clearInterval(this.intervalId);
    }
  }
}
 
export default Stream;