Created
November 22, 2016 15:48
-
-
Save kenchris/7f815230270db73e1bc3d7620721e629 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
function parseColor(colorStr) { | |
if (!this.div) { | |
this.div = document.createElement('div'); | |
this.div.style.hidden = true; | |
document.body.appendChild(this.div) | |
} | |
this.div.style.color = colorStr; | |
if (this.div.style.color === "") | |
this.div.style.color = `#${colorStr}`; | |
let style = window.getComputedStyle(this.div); | |
let colors = style.color.match(/\d+/g).map(a => parseInt(a, 10)); | |
return new Uint8Array(colors); | |
} | |
function withdelay(values, delay) { | |
return { | |
[Symbol.iterator]: function* () { | |
for (let i of values) { | |
yield new Promise(resolve => { | |
setTimeout(_ => resolve(i), delay); | |
}); | |
} | |
} | |
}; | |
} | |
async function run() { | |
for (let color of withdelay(["red", "purple", "blue"], 500)) { | |
console.log(parseColor(await color)); | |
} | |
} | |
//run() | |
async function run2() { | |
for (let color of ["green", "yellow", "rebeccapurple"]) { | |
let c = await new Promise(resolve => { | |
setTimeout(_ => resolve(color), 1000); | |
}) | |
console.log(parseColor(c)); | |
} | |
} | |
run2() | |
// noprotect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment