Skip to content

Instantly share code, notes, and snippets.

@hallettj
Last active January 23, 2022 21:27
Show Gist options
  • Save hallettj/0f50c26169173e8480a74e26104e2dfc to your computer and use it in GitHub Desktop.
Save hallettj/0f50c26169173e8480a74e26104e2dfc to your computer and use it in GitHub Desktop.
Lazily-evaluated promise example
// Run with: deno run lazy-promise.js
// See https://github.com/sindresorhus/p-lazy
import PLazy from "https://cdn.skypack.dev/p-lazy"
const a = new PLazy(resolve => {
console.log("this code does not execute")
resolve()
})
const b = new PLazy(resolve => {
console.log("this code executes when it is awaited")
resolve()
})
await b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment