Skip to content

Instantly share code, notes, and snippets.

Charles Lowell cowboyd

Block or report user

Report or block cowboyd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
cowboyd / wait-port.ts
Last active Dec 3, 2019
Waiting for a port with effection
View wait-port.ts
import { fork, timeout, Sequence, Operation } from 'effection';
import { on } from '@effection/events';
import { createConnection } from 'net';
export function* waitConnect(host: string, port: number): Sequence {
loop: {
let socket = createConnection(port, host);
let monitor = fork(function*() {
cowboyd / dump.js
Created Oct 30, 2019
Dump an effection `Fork`
View dump.js
export function dump(fork: any, indent = '') {
return `Fork {
state: ${fork.state}
operation: ${}
${[...fork.children].map(child => dump(child, ' ' + indent)).join("\n")}
}`.split("\n").map(line => `${indent}${line}`).join("\n");
cowboyd / node.js
Last active Sep 23, 2019
View node.js
import child_process from 'child_process';
* Continue a process once an event is received:
* ```ts
* yield untilEvent(mocha, 'onTestStarted');
function untilEvent(emitter, eventName) {
return execution => {
cowboyd / timebox.js
Last active Jul 29, 2019
Structured timeouts
View timebox.js
import { timeout } from 'effection';
* Run a process in a timebox. In other words, if the
* process does not complete within the specified time
* period, throw a timeout error.
export function timebox(durationMillis, proc) {
return function*() {
// fork the process
cowboyd / task-lifting.js
Last active Jul 19, 2019
What is the relationship between tasks and execution trees?
View task-lifting.js
import { execute, call } from 'effection';
// One of the things that struck me was that when I was doing the
// implementation for the `enqueue` function in the task constraining
// functions
// (,
// was the eventual form it took.
// Like the other task constructors, it returned a function. Let's
cowboyd / concurrency-constraining-functions.js
Last active Jul 17, 2019
construct stateful functions that can be called any number of times
View concurrency-constraining-functions.js
import { execute, timeout, call } from 'effection';
// Rather than shooting for some grandiose templating ability for
// concurrency (I still think we can get there, I just don't see how
// at the moment). What if we take a smaller step: Given some
// generator, how can we use it to generate a single function that can
// be called over and over and that internally it will manage a set of
// tasks instances for us?
cowboyd / otp-supervisors.js
Last active Jul 16, 2019
A draft implementation of OTP supervision strategies using generator based structured concurrency
View otp-supervisors.js
// implementation of Erlang genserver restart strategies on supervisor
// For demonstration purposes, the maximum restart intesity logic has been
// omitted. However, it would be straightforward to check restart intesity
// inside each catch block and use it to determine if the error should be
// instead rethrown.
* one_for_one - If one child process terminates and is to be
cowboyd / example.js
Created Jul 11, 2019
A function to execute a transaction on a microstate substate.
View example.js
let next = over(inventory.item.price, price => price.add(2).add(2).add(2));
cowboyd / 1-buildlog-successful-ns-bluetooth-1_3_1.txt
Last active May 7, 2019
Build Logs and Run Logs for before and after bluetooth upgrade
View 1-buildlog-successful-ns-bluetooth-1_3_1.txt
❯❯❯❯ yarn clean ~/C/N/exemplar 7327b0f
yarn run v1.13.0
$ rm -rf platforms *.aab *.ipa *.apk
✨ Done in 0.31s.
❯❯❯❯ rm -rf node_modules ~/C/N/exemplar 7327b0f
❯❯❯❯ yarn cache clean ~/C/N/exemplar 7327b0f
yarn cache v1.13.0
success Cleared cache.
✨ Done in 5.66s.
❯❯❯❯ yarn ~/C/N/exemplar 7327b0f
View count-to-five-a.js
import { call, variable, wait } from '@microstates/effects';
function* countToFive() {
let count = variable(1);, function*() { // the count variable is now the context of all operations
this.when(() => count.get() <= 5, function*() { // guard sees value of `count`
console.log(`count is ${count.get()}`);
yield wait(1000)
yield count.update(c => c + 1)
You can’t perform that action at this time.