This file contains 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
1 |
This file contains 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
<script src="https://github.com/grofers/ccq/releases/download/v0.1.0/ccq-0.1.0.min.js"></script> | |
<script> | |
new Queue() | |
.add(function(callback) { callback(null, 1); }) | |
.add(function(callback) { callback(null, 2); }) | |
.add(function(callback) { callback(null, 3); }) | |
.await(function(results) { console.log(results); }); | |
</script> |
This file contains 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
// 1) Start with the answer. 2) Move on to the Grubby Details. | |
// A viable try-able plan. | |
function sayIt(word) { | |
return TheSayItSaveItThing(word); | |
// Does Whatever-it-is-you-need-it-to. | |
// Loyal, Dependable, Weak-kneed. | |
function TheSayItSaveItThing(word) { | |
// When invoked it Saves. |
This file contains 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 _http_get(url) { | |
var deferred = Q.defer(); | |
http.get(url, deferred.resolve); | |
return deferred.promise; | |
} | |
function download(url, filepath, progressCallback, callback) { | |
//http.get() promisified using Q.nfcall() | |
return | |
_http_get(url) |
This file contains 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 download(url, filepath, progressCallback, callback) { | |
//http.get() promisified using Q.nfcall() | |
return | |
Q.nfcall(http.get, url) | |
.then(function(res) { | |
//Detecting a redirect the way request/request.js does it | |
if(res.statusCode >= 300 && res.statusCode < 400 && hasHeader(res, 'location')) { | |
//Get the new URL and make a fresh call to download, returning the promise | |
return download(getHeader(res, 'location'), filepath, progressCallback, callback); | |
} else { |
This file contains 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 download(url, filepath, progressCallback, callback) { | |
//The deferred object | |
var deferred = Q.defer(); | |
http.get(url, function(res) { | |
//Detecting a redirect the way request/request.js does it | |
if(res.statusCode >= 300 && res.statusCode < 400 && hasHeader(res, 'location')) { | |
//Get the new URL and make a fresh call to download, returning the promise | |
return download(getHeader(res, 'location'), filepath, progressCallback, callback); | |
} else { | |
var data = '', totalLength = parseInt(res.getHeader('content-length')); |
This file contains 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 downlaod(url, filepath, progressCallback, callback) { | |
http.get(url, function(res) { | |
//Detecting a redirect the way request/request.js does it | |
if(res.statusCode >= 300 && res.statusCode < 400 && hasHeader(res, 'location')) { | |
//Get the new URL and make a fresh call to download | |
download(getHeader(res, 'location'), filepath, progressCallback, callback); | |
} else { | |
var data = '', totalLength = parseInt(res.getHeader('content-length')); | |
var file = fs.createWriteStream(filepath); | |
res.pipe(file); |
This file contains 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 http = require('http'); | |
var Q = require('q'); | |
var download = function(url, callback) { | |
var page = ''; | |
var deferred = Q.defer(); | |
http.get(url, function(res) { | |
This file contains 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 http = require('http'); | |
var Q = require('q'); | |
var download = function(url) { | |
var page = ''; | |
var deferred = Q.defer(); | |
http.get(url, function(res) { | |
This file contains 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 http = require('http'); | |
var download = function(url, callback) { | |
var page = ''; | |
http.get(url, function(res) { | |
res.on('data', function(chunk) { | |
page += chunk.toString(); |