|
|
|
@ -3,22 +3,12 @@
|
|
|
|
|
const { validateArguments } = require("@validatem/core");
|
|
|
|
|
const required = require("@validatem/required");
|
|
|
|
|
|
|
|
|
|
const EndOfStream = require("@promistream/end-of-stream");
|
|
|
|
|
const simpleSource = require("@promistream/simple-source");
|
|
|
|
|
const fromLazyValue = require("@promistream/from-lazy-value");
|
|
|
|
|
|
|
|
|
|
module.exports = function createStreamFromValue(_value) {
|
|
|
|
|
let [ value ] = validateArguments(arguments, {
|
|
|
|
|
value: required
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let wasValueRead = false;
|
|
|
|
|
|
|
|
|
|
return simpleSource(() => {
|
|
|
|
|
if (wasValueRead === false) {
|
|
|
|
|
wasValueRead = true;
|
|
|
|
|
return value;
|
|
|
|
|
} else {
|
|
|
|
|
throw new EndOfStream("Value was read");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return fromLazyValue(() => value);
|
|
|
|
|
};
|
|
|
|
|