Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Callbags

 Callbags

Introduction to the "callbags" specification for lightweight observables & iterables.

Avatar for Stephan Schneider

Stephan Schneider

May 15, 2018
Tweet

More Decks by Stephan Schneider

Other Decks in Programming

Transcript

  1. What are callbags? • a contract how callbacks work in

    their context • similar to Node's error-first convention // error-first fs.readFile('/path/to/file', (err, data) => { ... }) // callbag source(0, (type, data) => { ... })
  2. Sources - produces data Terms → Sinks - consumes data

    → Operators - takes a source, returns a source →
  3. “End” - terminate the callbag “Start” - sent & received

    once as part of the handshake Design Principles 0 2 Type 1 “Data” - deliver data to the callbag
  4. • Call source with type === 0 • Callback is

    greeted back with type === 0 • “Talkback” allows sending data to source Handshake
  5. • type === 2 • Without second parameter: success •

    Anything truthy as second parameter: error Termination
  6. • type === 1 • Only after handshake • Only

    before termination Data Delivery
  7. • No central implementation • Anything that sticks to the

    interface is considered a callback • There’s no official standard lib • Everyone is invited to become an operator maintainer Governance
  8. Further reading • Wiki: https://github.com/callbag/callbag/wiki (contains a list of available

    utility packages) • Toolkit of commonly used operators: https://github.com/staltz/callbag-basics