Skip to content

Instantly share code, notes, and snippets.

On paternity leave - email me for anything urgent

Benjamin Gruenbaum benjamingr

On paternity leave - email me for anything urgent
View GitHub Profile
View async-iterator-cancellation.js
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
async function* delayedRange() {
try {
for(let i = 1; i <= 1000; i++) {
await delay(100);
yield i;
} catch (e) {
View mongo.js
// Let's say I have transaction code that looks like:
let state = 1;
session.withTransaction(async () => {
// this can retry, which means otherFn can run twice and possible insert the wrong value or in the wrong order
await Promise.all([
coll1.insertOne({ abc: 1 }, { session });
otherFn(state, session),
View chan.js
Makes a channel that buffers up to n items
function chan(n) {
const data = []; // data not yet read
const readersBacklog = []; // readers waiting for data
const writersBacklog = []; // writers waiting for data
let disposed = false;
// TODO(Benjamin) - disposing
View index.js
'use strict';
const { withToken, token } = require('./token.js');
const { setTimeout } = require('timers/promises');
const controller = withToken(() => {
setTimeout(100).then(() => {
View advent-5-input.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
View horrible-hack.js
'use strict';
// Extracted from v8/src/runtime/runtime.h
const methodNames = [

Who am I

Hi, I'm Benji, I'm a developer @ for the last year and a half. I was asked to write a little about how we work here at Other than that this is me on GitHub and Stack Overflow.

Developer Point of View.

Testim is an E2E functional test recording and playback tool. We automate the hard parts of end to end testing which are stability and fast authoring. In addition we provide a lot of useful root-cause analysis information for your tests.

View really_bad_idea.ts
// a non recursively assimilating promise without error recovery
class NonAssimilatingPromise<T, E> {
public value?: T;
constructor(value?: T, public error?: E) {
if (value) {
this.value = value;
then<T2, E2>(fn: (value: T) => NonAssimilatingPromise<T2, E2>): NonAssimilatingPromise<T2, E | E2> {
if (this.error) {
View bad_idea.js
class Throws<T> {
constructor(public error?: T) {
then<S>(fn: () => Throws<S>): Throws<T | S> {
if (this.error) {
// already errored, don't attempt to run the next action
return this;
const result = fn();
benjamingr /
Created Apr 16, 2019
What happens on a click
// actual differences (in chrome, IE, Firefox, Safari an Edge are all different) are:
// - behavior in disabled 'form' controls
// - phoning to home base (not here, it's defined elsewhere, can dig it up)
// - dealing with clicks dispatching clicks 'recursively'
// this is HTMLElement::click
void HTMLElement::click() {
DispatchSimulatedClick(nullptr, kSendNoEvents,