本文整理汇总了TypeScript中dojo-shim/Promise.reject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reject函数的具体用法?TypeScript reject怎么用?TypeScript reject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reject函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: close
/**
* Signals that the producer is done writing to the stream and wishes to move it to a "closed" state. The stream
* may have un-writted data queued; until the data has been written the stream will remain in the "closing" state.
*/
close(): Promise<void> {
// 4.2.4.5-1
if (!isWritableStream(this)) {
return Promise.reject(
new Error('WritableStream method called in context of object that is not a WritableStream instance')
);
}
// 4.2.4.5-2
if (this.state === State.Closed) {
return Promise.reject(new TypeError('Stream is already closed'));
}
if (this.state === State.Closing) {
return Promise.reject(new TypeError('Stream is already closing'));
}
if (this.state === State.Errored) {
// 4.2.4.5-3
return Promise.reject(this._storedError);
}
if (this.state === State.Waiting) {
// 4.2.4.5-4
this._resolveReadyPromise();
}
this._state = State.Closing;
this._queue.enqueue({ close: true }, 0);
this._advanceQueue();
return this._closedPromise;
}
示例2: abort
/**
* Signals that the producer can no longer write to the stream and it should be immediately moved to an "errored"
* state. Any un-written data that is queued will be discarded.
*/
abort(reason: any): Promise<void> {
// 4.2.4.4-1
if (!isWritableStream(this)) {
return Promise.reject(
new Error('WritableStream method called in context of object that is not a WritableStream instance')
);
}
if (this.state === State.Closed) {
// 4.2.4.4-2
return Promise.resolve();
}
if (this.state === State.Errored) {
// 4.2.4.4-3
return Promise.reject(this._storedError);
}
const error: Error = reason instanceof Error ? reason : new Error(reason);
this._error(error);
return util.promiseInvokeOrFallbackOrNoop(this._underlyingSink, 'abort', [ reason ], 'close')
.then(function () {
return;
});
}
示例3: write
/**
* Enqueue a chunk of data to be written to the underlying sink. `write` can be called successively without waiting
* for the previous write's promise to resolve. To respect the stream's backpressure indicator, check if the stream
* has entered the "waiting" state between writes.
*
* @returns A promise that will be fulfilled when the chunk has been written to the underlying sink.
*/
write(chunk: T): Promise<void> {
// 4.2.4.6-1
if (!isWritableStream(this)) {
return Promise.reject(
new Error('WritableStream method called in context of object that is not a WritableStream instance')
);
}
// 4.2.4.6-2
if (this.state === State.Closed) {
return Promise.reject(new TypeError('Stream is closed'));
}
if (this.state === State.Closing) {
return Promise.reject(new TypeError('Stream is closing'));
}
if (this.state === State.Errored) {
// 4.2.4.6-3
return Promise.reject(this._storedError);
}
let chunkSize = 1;
let writeRecord: Record<T> | undefined;
let promise = new Promise<void>(function (resolve, reject) {
writeRecord = {
chunk: chunk,
reject: reject,
resolve: resolve
};
});
// 4.2.4.6-6.b
try {
if (this._strategy && this._strategy.size) {
chunkSize = this._strategy.size(chunk);
}
this._queue.enqueue(writeRecord, chunkSize);
this._syncStateWithQueue();
}
catch (error) {
// 4.2.4.6-6.b, 4.2.4.6-10, 4.2.4.6-12
this._error(error);
return Promise.reject(error);
}
this._advanceQueue();
return promise;
}
示例4: start
start(): Promise<void> {
if (this._isClosed) {
return Promise.reject(new Error('Stream is closed'));
}
return Promise.resolve();
}
示例5: seek
seek(controller: ReadableStreamController<T>, position: number): Promise<number> {
if (position >= this.data.length || position < 0) {
let error = new Error('Invalid seek position: ' + position);
controller.error(error);
return Promise.reject(error);
}
this.currentPosition = position;
return Promise.resolve(this.currentPosition);
}
示例6: write
write(chunk: string): Promise<void> {
if (this._isClosed) {
return Promise.reject(new Error('Stream is closed'));
}
return new Promise<void>((resolve, reject) => {
this._rejectWritePromise = reject;
this._nodeStream.write(chunk, this._encoding, (error?: Error) => {
if (error) {
this._handleError(error);
}
else {
this._rejectWritePromise = undefined;
resolve();
}
});
});
}
示例7: seek
seek(position: number): Promise<number> {
if (this._underlyingSource.seek) {
return this._underlyingSource.seek(this.controller, position);
}
else {
if (this.reader && position < this.reader.currentPosition) {
return Promise.reject(new Error('Stream source is not seekable; cannot seek backwards'));
}
else {
let discardNext = (): Promise<number> => {
return this.reader.read().then((result: ReadResult<T>) => {
if (result.done || this.reader.currentPosition === position) {
return Promise.resolve(this.reader.currentPosition);
}
else {
return discardNext();
}
});
};
return discardNext();
}
}
}
示例8: function
sink.start = function() {
return Promise.reject(new Error('test error'));
};
示例9: function
return function () {
return Promise.reject(new Error('Unknown loader'));
};