Skip to content

Instantly share code, notes, and snippets.

{
"folders": [
{
// Path to Sway repo directory
"path": "./sway"
}
],
"extensions": {
"recommendations": [
// @flow
type Completion<TType: 'normal' | 'throw', TValue> = '/* internal */';
type NormalCompletion<TValue> = Completion<'normal', TValue>;
type ThrowCompletion<TValue> = Completion<'throw', TValue>;
function fetchNode() {
if (a) throw new NotAllowedError();
if (b) throw new NotFoundError();
if (c) return new ProfileNode();
# Helpers
ask() {
# http://djm.me/ask
local prompt default REPLY
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
@AlicanC
AlicanC / doWithRetries.js
Last active July 19, 2017 23:40
doWithRetries
/* @flow */
export default async function doWithRetries<TFnResolveValue>(
retryCount: number,
fn: () => Promise<TFnResolveValue>,
): Promise<TFnResolveValue> {
let retriesLeft = retryCount;
let lastError;
do {
@AlicanC
AlicanC / asyncComponentDidMount.js
Created February 27, 2016 14:50
A legacy decorator for React components with componentDidMount methods that do asynchronous tasks
import _ from 'lodash';
export default function asyncComponentDidMount(rejector = 'Component was unmounted.') {
return (component) => {
const cancelMap = new WeakMap();
const isCancelled = async (promise) => {
let cancelled = cancelMap.get(this);
if (cancelled) return cancelled;
/*
Queue
- Push task runners (async functions) to its "list"
- Run it
- Subscribe to its observable and wait for results
Runs "threadCount" amount of tasks in the "list"
When any of those tasks are completed, runs another task
If task #2 finishes before #1, it waits for #1 to finish and published before it publishes #2 so results are delivered in order