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.

41 lines
868 B
JavaScript

"use strict";
const pipe = require("@promistream/pipe");
const fromIterable = require("@promistream/from-iterable");
const simpleSink = require("./");
(async () => {
try {
let result = await pipe([
fromIterable([ 1, 2, 3, 4, 5 ]),
simpleSink({
onValue: async (value, abort) => {
console.log("value seen:", value);
// if (value === 3) { abort(new Error("uncomment this to trigger an abort")); }
},
onEnd: async () => {
console.log("stream finished");
return "arbitrary value";
},
onAbort: async (error) => {
console.log("stream aborted due to reason:", error);
}
})
]).read();
console.log("result:", result);
} catch (error) {
console.log("caught error:", error);
}
})();
/* Output:
value seen: 1
value seen: 2
value seen: 3
value seen: 4
value seen: 5
stream finished
result: arbitrary value
*/