Skip to content

Instantly share code, notes, and snippets.

@kaosat-dev
Created May 19, 2015 16:36
Show Gist options
  • Save kaosat-dev/4a0965c52b1c6b7af99f to your computer and use it in GitHub Desktop.
Save kaosat-dev/4a0965c52b1c6b7af99f to your computer and use it in GitHub Desktop.
Es6 Generators tests
function meshResolver(){
let _watchers = []
let inner = function*(){
let mesh = undefined
let value = mesh
//console.log("here in generator")
while(1){
value = yield mesh
if(value){
//console.log("got value",value)
mesh = value
}
}
}
let _inner = inner()
_inner.next()
function resolve(mesh)
{
_inner.next(mesh)
_watchers.map(function(watcher){
watcher.next()
})
}
return {
resolve:resolve,
promise:_inner,
addWatcher:function(watcher){
_watchers.push(watcher)
}
}
}
/////////////
let bla = meshResolver()
let gnak = function* (b){
//console.log("here",b)
let recievedValue = null
while(1){
yield b.next().value
console.log("reciever",b.next())
}
}
let g = gnak(bla.promise)
g.next()
bla.addWatcher(g)
console.log("GO")
//console.log(bla.promise.next())
//bla.resolve("bar")
//console.log(bla.promise.next())
//console.log(g.next())
//console.log(g.next())
setTimeout(function(){
console.log("in timeout")
bla.resolve("foo")
},1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment