Skip to content

Instantly share code, notes, and snippets.

Avatar

Alican Çubukçuoğlu AlicanC

View GitHub Profile
View flow-throws.js
// @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();
View gitClean.sh
# 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
View doWithRetries.js
/* @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 Feb 27, 2016
A legacy decorator for React components with componentDidMount methods that do asynchronous tasks
View asyncComponentDidMount.js
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;
View ordered-limited-promise-queue.js
/*
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
You can’t perform that action at this time.