UNPKG

@sqala/threedsecure-js

Version:

A vanilla library for implementing 3D Secure authentication flows in payment applications

48 lines (47 loc) 1.25 kB
var o = Object.defineProperty; var h = (e, t, r) => t in e ? o(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r; var s = (e, t, r) => h(e, typeof t != "symbol" ? t + "" : t, r); class c { constructor(t = []) { s(this, "error", null); s(this, "next", null); s(this, "bucket"); s(this, "abort"); this.stack = t, this.abort = new AbortController(), this.bucket = this.createBucket(); } get iterator() { return this.bucket; } close() { this.abort.abort(); } push(t) { if (this.abort.signal.aborted) throw new Error("Bucket is aborted"); if (!this.next) { this.stack.push(t); return; } const [r, i] = this.next; r(t), this.next = null; } pushError(t) { this.error = t; } async *createBucket() { for (; !this.abort.signal.aborted; ) yield new Promise((t, r) => { if (!this.stack.length) { this.next = [t, r]; return; } const i = this.stack.shift(); t(i); }), this.error && (yield Promise.reject(this.error), this.error = null); this.error && (yield Promise.reject(this.error), this.error = null); } } export { c as Bucket }; //# sourceMappingURL=bucket.js.map