1.2.0 • Published 8 years ago
pull-stream-protocol-checker v1.2.0
pull-stream-protocol-checker
Pull-stream module for detecting protocol violations at the interface of two modules.
Report an error if one of the following invariants is violated:
- No ask request (
read(false, ...)) after termination - Every callback is eventually invoked
- Every callback is invoked only once
- The callbacks are invoked in the order in which they were created
- No value answer (
cb(false, data)) after termination
Optionally can check:
- That no other request are made after the stream has terminated or was aborted
- The stream is eventually terminated
Usage
var checker = require('pull-stream-protocol-checker')
var pull = require('pull-stream')
var probe = checker()
pull(
pull.count(10),
probe,
pull.drain(null, function () {
probe.terminate()
})
)probe = checker(forbidExtraRequests, notifyEagerly)
forbidExtraRequests<Boolean>(Defaults tofalse)enforceStreamTermination<Boolean>(Defaults tofalse)notifyEagerly<Boolean>(Defaults totrue)
Invariant 5 is activated by setting forbidExtraRequests to true. Invariant 6 is activated by setting enforceStreamTermination to true. If notifyEagerly===true, an invariant violation is reported as an error that is thrown immediately; otherwise all violations are remembered and returned as an error array when invoking errors = probe.terminate().