Created
September 5, 2016 19:30
-
-
Save waldemarnt/9d086ee03ec2cbe1bfd0e90473b4b63f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loop = (gen, interval) => { | |
const point = gen.next(); | |
if(!point.done) { | |
return setTimeout(() => { | |
console.log(point.value); | |
loop(gen, interval); | |
}, interval); | |
} else { | |
console.log('done'); | |
} | |
}; | |
class Loop { | |
constructor(data, interval) { | |
this.data = data; | |
this.interval = interval; | |
} | |
generate() { | |
const data = this.data; | |
const gen = function*() { | |
yield* data; | |
}; | |
return loop(gen(), this.interval); | |
} | |
} | |
module.exports = Loop; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Loop = require('./loop'); | |
( | |
() => { | |
const data = [ | |
{ | |
lat: 1, | |
long: 2, | |
}, | |
{ | |
lat: 4, | |
long: 5, | |
}, | |
{ | |
lat: 2, | |
long: 3, | |
} | |
]; | |
const data2 = [ | |
{ | |
lat: 11, | |
long: 21, | |
}, | |
{ | |
lat: 41, | |
long: 51, | |
}, | |
{ | |
lat: 21, | |
long: 31, | |
} | |
]; | |
const loop = new Loop(data, 500); | |
loop.generate(); | |
const loop2 = new Loop(data2, 1500); | |
loop2.generate(); | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment