JSFiddle - React, Tailwind, and code Playground

by Farzad YZ

JavaScript

/* function interval(duration, onCycle) {
  let id;

  function* myGen(duration, onCycle) {
    const id = id = setInterval(() => {
      cycleGen.next()
    }, duration);
    while (true) {
      yield callback;
    }
  }

  let cycleGen = myGen(onCycle);

  return {
    start() {
      id = setInterval(() => {
        cycleGen.next()
      }, duration);
    },
    stop() {
      clearInterval(id);
      cycleGen.return();
    },
    pause() {

    },
    resume() {

    }
  }
} */

function* cycle(duration, onCycle) {
  const id = setInterval(() => {
    console.log('d')
    onCycle()
  }, duration);
  const result = {
  	start() {
    	result.next()
    },
    pause() {
    	yield  
    }
  }
  return {
  	start() {
    	
    }
  }
}

let x = cycle(1000, () => {
  console.log('cycle')
});

x.next()