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
Copyright 2011 Kristopher Michael Kowal. All rights reserved. | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to | |
deal in the Software without restriction, including without limitation the | |
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
sell copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. |
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 q = require('q'); | |
var a = q.defer(); | |
var b = q.defer(); | |
q.when(a, function() { | |
console.log('calling b'); | |
return q.when(b, function() { | |
console.log('throwing'); | |
throw new Error('Hello World'); |
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
"use strict"; | |
var Q = require("../q"); | |
exports['test spread'] = function (ASSERT, done) { | |
Q.ref([1,2,3]) | |
.spread(function (a, b, c) { | |
ASSERT.equal(a, 1, 'spread 1'); | |
ASSERT.equal(b, 2, 'spread 2'); | |
ASSERT.equal(c, 3, 'spread 3'); |
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 promiseResponse(request) { | |
var deferred = Q.defer(); | |
request.on("error", deferred.reject); | |
request.on("response", deferred.resolve); | |
return deferred.promise | |
// if you must: | |
.fin(function () { | |
request.removeListener("error", deferred.reject); | |
request.removeListener("response", deferred.resolve); | |
}); |
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 IO = require("q-io"); | |
function exists(id) { | |
var deferred = Q.defer(); | |
var request = knoxClient.get(id); | |
request.on("error", deferred.reject); | |
request.on("response", function (response) { | |
if (response.statusCode === 200) | |
deferred.resolve(IO.Reader(response)); | |
} 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
__all__ = ( | |
'build', | |
'endode', | |
'decode', | |
) | |
phrase = 'A man a plan a canal Panama'.lower() | |
def build(phrase): | |
""" |
By Deb White, Seattle, [NWRinger]
Can horses swim the Brandywine?
The Fellowship of the Ring, 112 the question of whether or not horses can cross the Brandywine River comes up at Buckleberry Ferry. We know that at least 1 hobbit pony can ride the ferry, as Merry takes his across on it when he searches for Frodo who is late to arrive; but there doesn’t seem to be an ability for them, either ponies or horses, to swim it at this point, they must go up to the Bridge or down to Sarn Ford, as Merry’s response to Frodo is: “Can horses cross the river?”
“They can go twenty miles north to Brandywine Bridge - or they might swim,” answered Merry, “Though I never heard of any horse swimming the Brandywine.”
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 DIR = '/tmp/test', | |
FILE_PATTERN = /test/, | |
fs = require('q-io/fs'); | |
fs.list(DIR) | |
.then(function (files) { | |
var matched = files.filter(function (item) { | |
return item.match(FILE_PATTERN); | |
}); | |
if (matched.length !== 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
const fs = require('fs') | |
function readPackage(callback) { | |
return fs.readFile('./package.json').nodeify(callback); | |
} | |
module.exports.readPackage = readPackage |