topsort-stream
Topological sort for streams
Example
var topsort =var dependencies =c: 'b'd: 'b' 'c'var s = 'stream'ssssss
Yields
a
b
c
d
'a' and 'b' where written to the destination stream after being read as they had no dependencies; 'a' first because it was read before 'b'. 'c' and 'd' depended on 'b' and written after; 'd' was written last becauese it dependend upon 'c'.
A real world example would be a gulp
plugin that is passed a nodeResolver
(see methods) that extracts the dependencies from metadata from the file content.
API
var topsort =
methods
var t = topsort(function nodeResolver(data) { return { [id: Object,] [deps: Array] } })
nodeResolver
defines the dependency graph bit assigning identity and dependencies to data.
events
t
inherits all all events from stream.Readable
.
t.on('topsort-error:resolving-node', cb)
The event fires when there is an error resolving a node.
t.on('topsort-error:unresolved-nodes', cb)
The event fires when the readable side of the stream is closed before all dependencies have been resolved. The call back is fired with an array of the ids of dependant nodes.
Install
npm install topsort-stream
license
MIT