Public
Edited
Jun 16, 2023
Insert cell
Insert cell
Synchrous.sleep(4).then(() => new Date())
Insert cell
Synchrous.idle(30).then(deadline => deadline.didTimeout ? "time out" : deadline.timeRemaining() / 1000)
Insert cell
// nesting
new Synchrous(a => a(new Synchrous(b => b(new Synchrous(c => c(new Date()))))))
Insert cell
// Thenable interface
new Map([null, 0, Synchrous.sleep(), Promises.tick(2)].map(v => [v, v instanceof Thenable]))
Insert cell
// error handling
new Synchrous((resolve, reject) => {
switch (Math.floor(Math.random() * 4)) {
case 0:
throw new Error("foo");
case 1:
reject(new Error("bar"));
default:
resolve(Math.PI);
}
}).then(n => n * 2)
Insert cell
Promise.all([
[
`new Thenable(a => a(NaN)).then(a => { throw a; })`,
new Promise(a => a(NaN)).then(a => { throw a; }),
new Synchrous(a => a(NaN)).then(a => { throw a; })
]
].map(async ([code, p, s]) => [code, (await Promise.allSettled([p])).shift(), s.result]))
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more