@ -18,18 +20,28 @@ module.exports = function simpleSource(_options) {
]);
leterrorReason;
letended=false;
letpeekQueue=[];
functiongetValue(){
returnPromise.try(()=>{
returnonRequest();
}).catch(isEndOfStream,(marker)=>{
ended=true;
throwmarker;
});
}
return{
description:`simple source`,
peek:functionpeekValue_simpleSource(){
returnPromise.try(()=>{
if(errorReason!=null){
if(errorReason!=null||ended===true){
returntrue;
}else{
// FIXME: Store Promises in the peekQueue instead? Or would this make it more difficult to deal with concurrent peeks/reads? And should the peek spec be changed to account for this?
returnPromise.try(()=>{
returnonRequest();
returngetValue();
}).then((result)=>{
peekQueue.push({type:"value",value:result});
}).catch((error)=>{
@ -62,8 +74,10 @@ module.exports = function simpleSource(_options) {
// FIXME: Pass in full error, after changing to a different error type implementation that accepts error objects as extra properties
thrownewAborted(`Stream was aborted due to error: ${errorReason.message}`,{reason:errorReason.message});