mirror of
https://github.com/JonasunderscoreJones/api.jonasjones.dev.git
synced 2025-10-23 20:19:19 +02:00
Initial commit (by create-cloudflare CLI)
This commit is contained in:
commit
58a42872a0
1745 changed files with 741893 additions and 0 deletions
51
node_modules/get-source/impl/SyncPromise.js
generated
vendored
Normal file
51
node_modules/get-source/impl/SyncPromise.js
generated
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
module.exports = class SyncPromise {
|
||||
|
||||
constructor (fn) {
|
||||
try {
|
||||
fn (
|
||||
x => { this.setValue (x, false) }, // resolve
|
||||
x => { this.setValue (x, true) } // reject
|
||||
)
|
||||
} catch (e) {
|
||||
this.setValue (e, true)
|
||||
}
|
||||
}
|
||||
|
||||
setValue (x, rejected) {
|
||||
this.val = (x instanceof SyncPromise) ? x.val : x
|
||||
this.rejected = rejected || ((x instanceof SyncPromise) ? x.rejected : false)
|
||||
}
|
||||
|
||||
static valueFrom (x) {
|
||||
if (x instanceof SyncPromise) {
|
||||
if (x.rejected) throw x.val
|
||||
else return x.val
|
||||
} else {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
||||
then (fn) {
|
||||
try { if (!this.rejected) return SyncPromise.resolve (fn (this.val)) }
|
||||
catch (e) { return SyncPromise.reject (e) }
|
||||
return this
|
||||
}
|
||||
|
||||
catch (fn) {
|
||||
try { if (this.rejected) return SyncPromise.resolve (fn (this.val)) }
|
||||
catch (e) { return SyncPromise.reject (e) }
|
||||
return this
|
||||
}
|
||||
|
||||
static resolve (x) {
|
||||
return new SyncPromise (resolve => { resolve (x) })
|
||||
}
|
||||
|
||||
static reject (x) {
|
||||
return new SyncPromise ((_, reject) => { reject (x) })
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue