本文整理汇总了TypeScript中ts-promise.Promise.resolve方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise.resolve方法的具体用法?TypeScript Promise.resolve怎么用?TypeScript Promise.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ts-promise.Promise
的用法示例。
在下文中一共展示了Promise.resolve方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
(enderError: Error) => {
// ender callback failed, but in order to let final stream fail,
// we need to pass 'something' on, and to wait for that to come
// back.
// Finally, make sure to return the enderError.
return Promise.resolve(defaultEnder(error || enderError)).then(
() => Promise.reject(enderError),
() => Promise.reject(enderError)
);
}
示例2: filterer
(v: T): void|Promise<void> => {
var b = filterer(v);
if (!b) {
return;
} else if (b === true) { // note: not just `if (b)`!
return writable.write(v);
} else { // more complex return type, probably a Thenable
return Promise.resolve(b).then((resolvedB) => {
if (resolvedB) {
return writable.write(v);
}
});
}
},
示例3: return
return (error?: Error) => {
// TODO: an error returned from ender is currently passed on to next
// stream, if stream was not ended with an error yet.
// It'd maybe be better to not have the next stream be ended when an
// error occurred in this ender, but there's no way to send another
// end(), so we have to close it somehow...
return Promise.resolve(error).then(ender).then(
() => defaultEnder(error),
(enderError: Error) => {
// ender callback failed, but in order to let final stream fail,
// we need to pass 'something' on, and to wait for that to come
// back.
// Finally, make sure to return the enderError.
return Promise.resolve(defaultEnder(error || enderError)).then(
() => Promise.reject(enderError),
() => Promise.reject(enderError)
);
}
);
};
示例4: Promise
"use strict";
import { Promise } from "ts-promise";
var prom = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(42);
// or e.g.: reject(new Error("boom"));
}, 100);
});
/// Hello world
Promise.resolve("test").then((v) => {
console.log(v);
});
var p = Promise.resolve();
/*
Promise.setLongTraces(true);
var p = Promise.resolve();
p.then(() => {
//return Promise.reject(new Error("my error"));
}).catch((e) => {
console.error(e.stack);
});
*/