Comparing version 2.0.0-alpha.18 to 2.0.0-alpha.19
@@ -7,3 +7,3 @@ import { Iterable } from 'dojo-shim/iterator'; | ||
}; | ||
export declare type ListOfPromises<T> = Iterable<(T | Thenable<T>)> | (T | Thenable<T>); | ||
export declare type ListOfPromises<T> = Iterable<(T | Thenable<T>)>; | ||
/** | ||
@@ -28,4 +28,4 @@ * An extensible base to allow Promises to be extended in ES5. This class basically wraps a native Promise object, | ||
*/ | ||
static resolve(): any; | ||
static resolve<T>(value: (T | Thenable<T>)): any; | ||
static resolve<F extends ExtensiblePromise<void>>(): F; | ||
static resolve<T, F extends ExtensiblePromise<T>>(value: (T | Thenable<T>)): F; | ||
/** | ||
@@ -45,2 +45,4 @@ * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value | ||
}>, T>(iterable: DictionaryOfPromises<T>): F; | ||
static all<F extends ExtensiblePromise<T[]>, T>(iterable: (T | Thenable<T>)[]): F; | ||
static all<F extends ExtensiblePromise<T[]>, T>(iterable: T | Thenable<T>): F; | ||
static all<F extends ExtensiblePromise<T[]>, T>(iterable: ListOfPromises<T>): F; | ||
@@ -79,3 +81,3 @@ /** | ||
*/ | ||
catch<U>(onRejected: (reason: Error) => (U | Thenable<U>)): this; | ||
catch(onRejected: (reason: Error) => T | Thenable<T> | void): ExtensiblePromise<T>; | ||
/** | ||
@@ -89,3 +91,4 @@ * Adds a callback to be invoked when the wrapped Promise resolves or is rejected. | ||
*/ | ||
then<U>(onFulfilled?: ((value: T) => (U | Thenable<U> | undefined)) | undefined, onRejected?: (reason: Error) => void): this; | ||
then<U, V>(onFulfilled: ((value: T) => (U | Thenable<U> | undefined)) | undefined, onRejected: (reason: Error) => (V | Thenable<V>)): ExtensiblePromise<U | V>; | ||
then<U>(onFulfilled?: ((value: T) => (U | Thenable<U> | undefined)) | undefined, onRejected?: (reason: Error) => void): ExtensiblePromise<U>; | ||
} |
import { Thenable } from 'dojo-shim/interfaces'; | ||
import { Executor } from 'dojo-shim/Promise'; | ||
import ExtensiblePromise from './ExtensiblePromise'; | ||
import ExtensiblePromise, { ListOfPromises, DictionaryOfPromises } from './ExtensiblePromise'; | ||
import { Iterable } from 'dojo-shim/iterator'; | ||
/** | ||
@@ -29,2 +30,16 @@ * Describe the internal state of a task. | ||
/** | ||
* Return a Task that resolves when one of the passed in objects have resolved | ||
* | ||
* @param iterable An iterable of values to resolve. These can be Promises, ExtensiblePromises, or other objects | ||
* @returns {Task} | ||
*/ | ||
static race<F extends ExtensiblePromise<T>, T>(iterable: Iterable<(T | Thenable<T>)> | (T | Thenable<T>)[]): Task<T>; | ||
/** | ||
* Return a rejected promise wrapped in a Task | ||
* | ||
* @param {Error?} reason The reason for the rejection | ||
* @returns {Task} | ||
*/ | ||
static reject<T>(reason?: Error): Task<T>; | ||
/** | ||
* Return a resolved task. | ||
@@ -38,2 +53,8 @@ * | ||
static resolve<T>(value: (T | Thenable<T>)): Task<T>; | ||
static all<T>(iterable: DictionaryOfPromises<T>): Task<{ | ||
[key: string]: T; | ||
}>; | ||
static all<T>(iterable: (T | Thenable<T>)[]): Task<T[]>; | ||
static all<T>(iterable: T | Thenable<T>): Task<T[]>; | ||
static all<T>(iterable: ListOfPromises<T>): Task<T[]>; | ||
/** | ||
@@ -78,2 +99,3 @@ * A cancelation handler that will be called if this task is canceled. | ||
cancel(): void; | ||
catch(onRejected: (reason: Error) => T | Thenable<T> | void): Task<T>; | ||
/** | ||
@@ -91,3 +113,5 @@ * Allows for cleanup actions to be performed after resolution of a Promise. | ||
*/ | ||
then<U>(onFulfilled?: (value?: T) => U | Thenable<U>, onRejected?: (error: Error) => U | Thenable<U>): this; | ||
then<U, V>(onFulfilled: ((value: T) => (U | Thenable<U> | undefined)) | undefined, onRejected: (reason: Error) => (V | Thenable<V>)): Task<U | V>; | ||
then<U>(onFulfilled?: ((value: T) => (U | Thenable<U> | undefined)) | undefined, onRejected?: (reason: Error) => void): Task<U>; | ||
then<U>(onFulfilled?: ((value: T) => (U | Thenable<U> | undefined)) | undefined, onRejected?: (reason: Error) => (U | Thenable<U>)): Task<U>; | ||
} |
@@ -86,5 +86,26 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
} | ||
/** | ||
* Return a Task that resolves when one of the passed in objects have resolved | ||
* | ||
* @param iterable An iterable of values to resolve. These can be Promises, ExtensiblePromises, or other objects | ||
* @returns {Task} | ||
*/ | ||
Task.race = function (iterable) { | ||
return _super.race.call(this, iterable); | ||
}; | ||
/** | ||
* Return a rejected promise wrapped in a Task | ||
* | ||
* @param {Error?} reason The reason for the rejection | ||
* @returns {Task} | ||
*/ | ||
Task.reject = function (reason) { | ||
return new this(function (resolve, reject) { return reject(reason); }); | ||
}; | ||
Task.resolve = function (value) { | ||
return new this(function (resolve, reject) { return resolve(value); }); | ||
}; | ||
Task.all = function (iterable) { | ||
return _super.all.call(this, iterable); | ||
}; | ||
Object.defineProperty(Task.prototype, "state", { | ||
@@ -134,2 +155,5 @@ get: function () { | ||
}; | ||
Task.prototype.catch = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; | ||
/** | ||
@@ -150,10 +174,2 @@ * Allows for cleanup actions to be performed after resolution of a Promise. | ||
}; | ||
/** | ||
* Adds a callback to be invoked when the Task resolves or is rejected. | ||
* | ||
* @param {Function} onFulfilled A function to call to handle the resolution. The paramter to the function will be the resolved value, if any. | ||
* @param {Function} onRejected A function to call to handle the error. The parameter to the function will be the caught error. | ||
* | ||
* @returns {ExtensiblePromise} | ||
*/ | ||
Task.prototype.then = function (onFulfilled, onRejected) { | ||
@@ -160,0 +176,0 @@ var _this = this; |
{ | ||
"name": "dojo-core", | ||
"version": "2.0.0-alpha.18", | ||
"version": "2.0.0-alpha.19", | ||
"description": "Basic utilites for common TypeScript development", | ||
@@ -21,4 +21,3 @@ "engines": { | ||
"dojo-has": ">=2.0.0-alpha.6", | ||
"dojo-shim": ">=2.0.0-alpha.4", | ||
"dojo-streams": ">=2.0.0-alpha.1" | ||
"dojo-shim": ">=2.0.0-alpha.4" | ||
}, | ||
@@ -25,0 +24,0 @@ "devDependencies": { |
import { RequestOptions, ResponsePromise } from '../request'; | ||
import WritableStream from 'dojo-streams/WritableStream'; | ||
export interface NodeRequestOptions<T> extends RequestOptions { | ||
@@ -25,3 +24,2 @@ agent?: any; | ||
streamEncoding?: string; | ||
streamTarget?: WritableStream<T>; | ||
redirectOptions?: { | ||
@@ -28,0 +26,0 @@ limit?: number; |
@@ -8,3 +8,3 @@ (function (dependencies, factory) { | ||
} | ||
})(["require", "exports", "../async/Task", "./errors/RequestTimeoutError", "http", "https", "../lang", "dojo-streams/adapters/ReadableNodeStreamSource", "dojo-streams/adapters/WritableNodeStreamSink", "dojo-streams/ReadableStream", "dojo-streams/WritableStream", "url", "./util"], function (require, exports) { | ||
})(["require", "exports", "../async/Task", "./errors/RequestTimeoutError", "http", "https", "../lang", "url", "./util"], function (require, exports) { | ||
"use strict"; | ||
@@ -16,6 +16,2 @@ var Task_1 = require("../async/Task"); | ||
var lang_1 = require("../lang"); | ||
var ReadableNodeStreamSource_1 = require("dojo-streams/adapters/ReadableNodeStreamSource"); | ||
var WritableNodeStreamSink_1 = require("dojo-streams/adapters/WritableNodeStreamSink"); | ||
var ReadableStream_1 = require("dojo-streams/ReadableStream"); | ||
var WritableStream_1 = require("dojo-streams/WritableStream"); | ||
var urlUtil = require("url"); | ||
@@ -196,20 +192,2 @@ var util_1 = require("./util"); | ||
options.streamEncoding && nativeResponse.setEncoding(options.streamEncoding); | ||
if (options.streamTarget) { | ||
var responseSource = new ReadableNodeStreamSource_1.default(nativeResponse); | ||
var responseReadableStream = new ReadableStream_1.default(responseSource); | ||
responseReadableStream.pipeTo(options.streamTarget) | ||
.then(function () { | ||
resolve(response); | ||
}, function (error) { | ||
if (options.streamTarget) { | ||
// abort the stream, swallowing any errors, | ||
// (because we've already got an error, and we can't catch this one) | ||
options.streamTarget.abort(error).catch(function () { | ||
}); | ||
} | ||
request.abort(); | ||
error.response = response; | ||
reject(error); | ||
}); | ||
} | ||
var data; | ||
@@ -233,10 +211,3 @@ var loaded; | ||
} | ||
// If using a streamTarget, wait for it to finish in case it throws an error | ||
if (!options.streamTarget) { | ||
resolve(response); | ||
} | ||
else { | ||
options.streamTarget.close().catch(function () { | ||
}); | ||
} | ||
resolve(response); | ||
}); | ||
@@ -246,16 +217,3 @@ }); | ||
if (options.data) { | ||
if (options.data instanceof ReadableStream_1.default) { | ||
var requestSink = new WritableNodeStreamSink_1.default(request); | ||
var writableRequest_1 = new WritableStream_1.default(requestSink); | ||
options.data.pipeTo(writableRequest_1) | ||
.catch(function (error) { | ||
error.response = response; | ||
writableRequest_1.abort(error).catch(function () { | ||
}); | ||
reject(error); | ||
}); | ||
} | ||
else { | ||
request.end(options.data); | ||
} | ||
request.end(options.data); | ||
} | ||
@@ -262,0 +220,0 @@ else { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
487602
2
108
5397