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