Skip to content

Instantly share code, notes, and snippets.

@elzup
Created October 1, 2021 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elzup/80dfe7bff7b39cb12c34d2c8343bf8ea to your computer and use it in GitHub Desktop.
Save elzup/80dfe7bff7b39cb12c34d2c8343bf8ea to your computer and use it in GitHub Desktop.
import { promisify } from 'util'
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms))
const argSwap = <A1, A2, R>(f: (a1: A1, a2: A2) => R) => (a2: A2, a1: A1) =>
f(a1, a2)
const sleep2 = promisify((ms, cb) => setTimeout(cb, ms))
const sleep3 = promisify(argSwap(setTimeout))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment