This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/papercraft/openjscad/node_modules/most/lib/combinator/continueWith.js

80 lines
2.1 KiB
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.continueWith = continueWith;
var _Stream = require('../Stream');
var _Stream2 = _interopRequireDefault(_Stream);
var _Pipe = require('../sink/Pipe');
var _Pipe2 = _interopRequireDefault(_Pipe);
var _dispose = require('../disposable/dispose');
var dispose = _interopRequireWildcard(_dispose);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function continueWith(f, stream) {
return new _Stream2.default(new ContinueWith(f, stream.source));
} /** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
function ContinueWith(f, source) {
this.f = f;
this.source = source;
}
ContinueWith.prototype.run = function (sink, scheduler) {
return new ContinueWithSink(this.f, this.source, sink, scheduler);
};
function ContinueWithSink(f, source, sink, scheduler) {
this.f = f;
this.sink = sink;
this.scheduler = scheduler;
this.active = true;
this.disposable = dispose.once(source.run(this, scheduler));
}
ContinueWithSink.prototype.error = _Pipe2.default.prototype.error;
ContinueWithSink.prototype.event = function (t, x) {
if (!this.active) {
return;
}
this.sink.event(t, x);
};
ContinueWithSink.prototype.end = function (t, x) {
if (!this.active) {
return;
}
dispose.tryDispose(t, this.disposable, this.sink);
this._startNext(t, x, this.sink);
};
ContinueWithSink.prototype._startNext = function (t, x, sink) {
try {
this.disposable = this._continue(this.f, x, sink);
} catch (e) {
sink.error(t, e);
}
};
ContinueWithSink.prototype._continue = function (f, x, sink) {
return f(x).source.run(sink, this.scheduler);
};
ContinueWithSink.prototype.dispose = function () {
this.active = false;
return this.disposable.dispose();
};