@grammyjs/conversations
Version:
Conversational interfaces for grammY
25 lines (24 loc) • 792 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolver = resolver;
/**
* Creates a new resolver.
*
* Optionally accepts a value to which the promise will resolve when `resolve`
* is called without arguments. Note that the value will be discarded if
* `resolve` is called with an argument.
*
* @param value An optional default to resolve to when calling `resolve`
*/
function resolver(value) {
const rsr = { value, isResolved: () => false };
rsr.promise = new Promise((resolve) => {
rsr.resolve = (t = value) => {
rsr.isResolved = () => true;
rsr.value = t;
resolve(t); // cast to handle void
rsr.resolve = () => { }; // double resolve is no-op
};
});
return rsr;
}