You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
"use strict";
|
|
|
|
const propagateAbort = require("@promistream/propagate-abort");
|
|
const pushBuffer = require("push-buffer");
|
|
|
|
module.exports = function sequentialize() {
|
|
let lastKnownSource;
|
|
|
|
let readBuffer = pushBuffer({
|
|
sequential: true,
|
|
pull: async () => {
|
|
return lastKnownSource.read();
|
|
}
|
|
});
|
|
|
|
let peekBuffer = pushBuffer({
|
|
sequential: true,
|
|
pull: async () => {
|
|
return lastKnownSource.peek();
|
|
}
|
|
});
|
|
|
|
return {
|
|
_promistreamVersion: 0,
|
|
description: `sequentialize`,
|
|
// FIXME: We don't queue up aborts because once a downstream has encountered an error, it may have stopped trying to read, and we would deadlock. While the Aborted marker reads *do* get queued, the abort itself should probably be immediate. Need to make sure that this doesn't clash with any other part of the spec.
|
|
abort: propagateAbort,
|
|
peek: function peek(source) {
|
|
lastKnownSource = source;
|
|
return peekBuffer.request();
|
|
},
|
|
read: function read(source) {
|
|
lastKnownSource = source;
|
|
return readBuffer.request();
|
|
}
|
|
};
|
|
};
|