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 promiseDoWhilst = require('promise-do-whilst'); | |
var Board = require('firmata'); | |
var Promise = require('bluebird'); | |
let gBoard = null; | |
// returns a promised of a connectable port | |
let firmataRequestPort = () => { | |
return Promise.try(() => { | |
return new Promise((resolve, reject) => { |
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 Promise = require('bluebird') | |
let myDelay = (ms) => { | |
let milliseconds = ms; | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(); | |
}, milliseconds) | |
}); | |
}; |
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
thisFunctionReturnsAPromise() | |
.then((result) => { | |
console.log("We'll be right back..."); | |
}) | |
.delay(500) | |
.then(() => { | |
console.log("We're back!"); | |
}) |
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
let delay = (ms) => { | |
return new Promise( (resolve, reject) => { | |
setTimeout(() => { resolve(); }, ms); | |
}); | |
}; | |
let digitalRead = (thePin) => { | |
return new Promise((resolve, reject) => { | |
gBoard.digitalRead(thePin, function(value){ | |
resolve(value); |
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
setInterval(() => { | |
new Promise((resolve, reject) => { | |
... | |
resolve(value); | |
... | |
}).then((value) => { ... }); | |
}, 100); |
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
<form name="myForm"> | |
<label for="duration"> Duration: </label><br> | |
<select name="duration" ng-model="selectedDuration" ng-change="durationChange()"> | |
<option ng-repeat="(key, value) in durations" value="{{value}}" selected="{{isSelectedDurationOption(value)}}"> | |
{{key}} | |
</option> | |
</select> | |
</form> |
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
gulp.task("babel-routes", function () { | |
return gulp.src("routes/*.es6") | |
.pipe(babel()) | |
.pipe(gulp.dest("routes/")); | |
}); | |
gulp.task("babel-public-javascripts", function () { | |
return gulp.src("public/javascripts/**/*.es6") | |
.pipe(babel()) | |
.pipe(gulp.dest("public/javascripts/")); |
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 config = require('../../eggdataconfig')(); | |
var express = require('express'); | |
var router = express.Router(); | |
var Promise = require("bluebird"); | |
var bhttp = Promise.promisifyAll(require("bhttp")); | |
function urlParams(params){ | |
var ret = ""; | |
if(Object.keys(params).length > 0){ // if there are any optional params | |
ret += '?'; |
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
return Promise.try(function () { | |
//return fs.readFileAsync(status.filename, 'utf8'); | |
return MongoClient.connectAsync(MONGODB_CONNECTION_STRING).then(function(db){ | |
var results = null; | |
return Promise.try(function(){ | |
return db.collection("downloads").findOneAsync({key: status.filename}); | |
}).then(function(item){ | |
results = item; | |
return db.closeAsync(); | |
}).then(function(){ |
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
return Promise.try(function () { | |
//return fs.readFileAsync(status.filename, 'utf8'); | |
return MongoClient.connectAsync(MONGODB_CONNECTION_STRING) | |
.then(function(db){ | |
return db.collection("downloads").findOneAsync({key: status.filename}); | |
}); | |
}).then(function(content) { | |
// ... | |
}); |