Skip to content

Instantly share code, notes, and snippets.

import { summary, bench, run, do_not_optimize } from 'mitata';
bench('noop', () => { });
bench('noop', () => { });
bench('noop', () => { });
summary(() => {
{
const fn = (a: number, b: number) => a * 2 + b + Math.random();
do_not_optimize(fn);
declare const _: unique symbol;
export interface Redacted<out T> extends Symbol {
[_]: T
}
const redactMap = new WeakMap();
export const init = <const T>(val: T): Redacted<T> => {
const sym = Symbol('<redacted>');
redactMap.set(sym, val);
const getFinishedState = async (s: [string], p: Promise<any>) => {
try {
await p;
s[0] = 'resolved';
} catch (e) {
s[0] = 'rejected';
// Don't swallow error
return p;
}
{
// DisposableStack fork
using parentStack = new DisposableStack();
const childStack = parentStack.use(new DisposableStack());
// DisposableStack register with dispose callback (should be cached)
const stack = new DisposableStack();
stack.adopt(resource, (resource) => {
// Dispose resource
});