-
-
Save EarlGeorge/d5d3950222c1834aebb042ef164cee53 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 delay = require('delay') | |
async function* makeCountingObservable() { | |
let count = 0 | |
while(true) { | |
if (count > 4) return | |
await delay(1000) | |
yield count++ | |
} | |
} | |
const counter = makeCountingObservable() | |
;(async function() { | |
let lastIterat | |
while(true) { | |
lastIterated = await counter.next() | |
if (lastIterated.done) return | |
console.log(lastIterated.value) | |
} | |
for await (const num of counter) { | |
console.log(num) | |
} | |
})() | |
const greetings = ['hej', 'oi', 'hello'] | |
for(const greeting of greetings) { | |
console.log(greeting) | |
} | |
function makeCountingStream() { | |
let count = 0 | |
let handler = null | |
setInterval(function() { | |
count++ | |
handler(count) | |
}, 500) | |
return { | |
each: function(callback) { | |
handler = callback | |
} | |
} | |
} | |
const stream = makeCountingStream() | |
stream.each(function(message) { | |
console.log(message) | |
}) | |
function makeValueAfterOneSecondPromise() { | |
return { | |
then: function(callback) { | |
setTimeout(function() { | |
callback("hello") | |
}, 1000) | |
} | |
} | |
} | |
const promise = makeValueAfterOneSecondPromise() | |
promise.then(function(message) { | |
message //? | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment