Skip to content

Instantly share code, notes, and snippets.

@blacksun1
Created August 9, 2016 07:02
Show Gist options
  • Save blacksun1/bd9fef0dde99344ff221b0bcfa2a94c2 to your computer and use it in GitHub Desktop.
Save blacksun1/bd9fef0dde99344ff221b0bcfa2a94c2 to your computer and use it in GitHub Desktop.
"use strict";
const Q = require("q");
Q.async(function*(){
let promiseResults = [];
try {
promiseResults.push([new Date(), yield Q.resolve("Done?")]);
promiseResults.push([new Date(), yield(Q.delay("Done 1", 1000))]);
promiseResults.push([new Date(), yield(Q.delay("Done 2", 1000))]);
promiseResults.push([new Date(), yield(Q.delay("Done 3", 1000))]);
promiseResults.push([new Date(), yield(Q.delay("Done 4", 1000))]);
promiseResults.push(yield(Q.reject(new Error("Ooops!"))));
} catch(err) {
console.error("Error:", err);
console.error(err.stack);
}
const dataMap = promiseResults.map(x => [x[0].toTimeString(), x[1]]);
console.log(dataMap);
return "Cheese cake";
})()
.then(result => console.log("Promise returned OK:", result))
.catch(error => console.error("Error occurred:", error))
.done();
Q.when(
Q.delay(10, 1000), x => console.log(x)
)
.done();
{
"name": "generator-test",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "blacksun1 <blacksun1@users.noreply.github.com>",
"license": "MIT",
"dependencies": {
"q": "^1.4.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment