Skip to content

Instantly share code, notes, and snippets.

@CrabDude
Last active December 20, 2019 18:50
Show Gist options
  • Save CrabDude/10907185 to your computer and use it in GitHub Desktop.
Save CrabDude/10907185 to your computer and use it in GitHub Desktop.
Node.js Callback Contract

Node.js Callback* Contract

(aka "errback" or "error first callback")

  1. Function that takes 2 arguments
    • first argument is an error
    • second argument is the result
    • Never pass both
    • error should be instanceof Error
  2. Must never excecute on the same tick of the event loop
  3. Must be passed as last argument to function
  4. Return value is ignored
  5. Must not throw / must pass resulting errors
  6. Must never be called more than once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment