Skip to content

Instantly share code, notes, and snippets.

Avatar

Charles Lowell cowboyd

View GitHub Profile
@cowboyd
cowboyd / experiment.ts
Last active Aug 10, 2022
Effection 3 effects/resources as continuations
View experiment.ts
import { Operation, run, effect, sleep } from "./mod.ts";
interface Num {
value: number;
incrementSlowly(): Operation<void>;
}
function useNum(initial: number) {
return effect<Num>(function*(provide) {
let value = initial;
@cowboyd
cowboyd / README.md
Last active May 6, 2022
Contains pass / fail terminal output. Both raw, and rendered to html
View README.md

In order to generate html from terminal output, you can use this tool https://github.com/buildkite/terminal-to-html to do it in two steps.

Capture

First, run your command, and save it to a raw output file.

$ mycommand > output.term
@cowboyd
cowboyd / promises
Last active Feb 18, 2022
Stream promises using effection
View promises
import { createStream } from 'effection';
// create an effection stream out of an array of promises
// https://frontside.com/effection/docs/guides/collections
export function producer(promises) {
return createStream(publish => {
for (let promise of promises) {
promise.then(publish);
}
});
@cowboyd
cowboyd / main.js
Created Nov 29, 2021
Effection Workers
View main.js
const { once, spawn, main, on, createChannel } = require('effection');
const { Worker } = require('worker_threads');
main(function* () {
const worker1 = yield createWorker('./worker1.js');
const worker2 = yield createWorker('./worker2.js');
yield spawn(function*() {
const interval = setInterval(() => {
worker2.worker.postMessage({ t: 'getValue' }); // ticker
@cowboyd
cowboyd / 1-click-to-load.js
Last active Nov 15, 2021
Handle a stream of clicks by canceling the latest one
View 1-click-to-load.js
/**
* Implements an operation to fetch the data as described in https://twitter.com/BenLesh/status/1455597411385098242
* The "winner" is unambiguous. It is the request corresponding to the latest click, guaranteed.
* Other important things to note:
*
* 1. The HTTP request is cancelled every time along with its containing task
* 2. click listener is removed automatically at the end of the `clickToLoad` operation
* 3. The cancellation logic is explicit here to demonstrate the concept, but it can easily be abstracted into a separate
*. function. See the `click-to-load-HOF` example below
*/
@cowboyd
cowboyd / graphgen-relay.ts
Created Sep 28, 2021
Creating a Relay page from a graphgen edge type
View graphgen-relay.ts
import { Vertex } from '@frontside/graphgen';
export interface PageArgs {
first?: number;
before?: string;
last?: number;
after: string;
}
export interface PageInfo {
@cowboyd
cowboyd / spawn-point.ts
Last active Sep 23, 2021
Creating a spawn point that will enqueue a build
View spawn-point.ts
import { createQueue, main, on, Operation, Resource } from 'effection';
import { daemon, exec, Process } from '@effection/process';
import { watch } from 'chokidar';
main(function*() {
let watcher = watch('./src/**/*.ts', { ignoreInitial: true, ignored: 'dist' });
try {
let build = yield createSpawnPoint(start);
@cowboyd
cowboyd / debug.ts
Last active May 21, 2021
Rudimentary Effection debug API
View debug.ts
// pause
// -- suspend at the next point
// play
// -- unsuspend and you are now free to do
// step
// -- unspend, but suspend at the next point
import { main } from './main';
import { once, Operation } from 'effection';
import { EventEmitter } from 'events';
@cowboyd
cowboyd / everboil.md
Created May 12, 2021
Thoughts on evergreen boiler-plate configuration
View everboil.md

Thoughts on evolving project boilerplate

Projects are bootstrapped with templates, and so before we can talk about evolving project boilerplate, we have to first talk about how templates work.

What is a template really?

We can represent the rendering of a template T into an artifact a with the equation

a = T(v)
@cowboyd
cowboyd / supervisor.ts
Created Mar 17, 2021
potential supervisor in effection
View supervisor.ts
import { Task, Operation } from 'effection';
interface SupervisorOptions {
maxConcurrency?: number;
dropMostRecent?: boolean;
}
const supervisorDefaults = {
maxConcurrency: 1,
dropMostRecent: true