MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / emitDataEvents

Function emitDataEvents

MathBox/mathbox-core.js:3668–3715  ·  view source on GitHub ↗
(stream, startPaused)

Source from the content-addressed store, hash-verified

3666};
3667
3668function emitDataEvents(stream, startPaused) {
3669 var state = stream._readableState;
3670
3671 if (state.flowing) {
3672 // https://github.com/isaacs/readable-stream/issues/16
3673 throw new Error('Cannot switch to old mode now.');
3674 }
3675
3676 var paused = startPaused || false;
3677 var readable = false;
3678
3679 // convert to an old-style stream.
3680 stream.readable = true;
3681 stream.pipe = Stream.prototype.pipe;
3682 stream.on = stream.addListener = Stream.prototype.on;
3683
3684 stream.on('readable', function() {
3685 readable = true;
3686
3687 var c;
3688 while (!paused && (null !== (c = stream.read())))
3689 stream.emit('data', c);
3690
3691 if (c === null) {
3692 readable = false;
3693 stream._readableState.needReadable = true;
3694 }
3695 });
3696
3697 stream.pause = function() {
3698 paused = true;
3699 this.emit('pause');
3700 };
3701
3702 stream.resume = function() {
3703 paused = false;
3704 if (readable)
3705 setImmediate(function() {
3706 stream.emit('readable');
3707 });
3708 else
3709 this.read(0);
3710 this.emit('resume');
3711 };
3712
3713 // now make it start, just in case it hadn't already.
3714 stream.emit('readable');
3715}
3716
3717// wrap an old-style stream as the async data source.
3718// This is *not* part of the readable stream interface.

Callers 2

flowFunction · 0.70
mathbox-core.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected