History

Devnull

You need to understand what a pipe and stream step in that pipe is AND nothing comes for free. The cost of working with large amounts of data in near real-time environments with RStreams is you have to think about what you are doing and what it means with respect to reading and writing. It is strongly recommended you read the Read/Write at Scale article at some point.

API Doc

This function creates a sink stream whose purpose is simply to pull events downstream and do nothing with them. All pipes have to have a sink or nothing flows in the pipe since the sink pulls data along from the upstream step before it and then that step pulls from its antecedent and so on. So, no sink means nothing moves in the pipe. However, you don’t always want your sink to actually do work like write to a file or to a database or another queue and so devnull is your answer.

When would I use this?

  • When you have a pipe where all you want to do is log data moving through the pipe
  • When you have a pipe that does processing in one of the stream steps before the sink

Runnable Examples

Example 1

This example uses the very popular event-stream Node library, which is exported via the SDK it’s used so much, to turn a hard-coded array into a source stream to feed the pipe.

Then, devnull is used since we don’t really want to do anything more than log the events moving through the stream.

The argument to devnull, if true, will log events that come to the sink. You can also pass a string in which tells the SDK to log events and starts each event in the console output with the string you provided and not the word “devnull” which is the default behavior.

Example 1 code
 1import { RStreamsSdk } from "leo-sdk";
 2
 3async function main() {
 4  const rsdk: RStreamsSdk  = new RStreamsSdk();
 5
 6  const DATA: SoftDrink[] = [
 7    {name: 'Pepsi', yearInvented: 1893},
 8    {name: 'Coca-Cola', yearInvented: 1886},
 9    {name: 'Dr Pepper', yearInvented: 1885},
10    {name: 'Hires Root Beer', yearInvented: 1876},
11    {name: 'Vernors Ginger Ale', yearInvented: 1866},
12    {name: 'Schweppes', yearInvented: 1783}
13  ]
14
15  await rsdk.streams.pipeAsync(
16    rsdk.streams.eventstream.readArray(DATA),
17    rsdk.streams.devnull(true)
18  );
19}
20
21interface SoftDrink {
22    name: string;
23    yearInvented: number;
24}
25
26(async () => {
27  try {
28    await main();
29  } catch(err) {
30    console.log(err);
31  }
32})()
Example 1 console output
 1➜  rstreams-runnable-examples ts-node apps/devnull-stream.ts 
 2devnull {
 3  "name": "Pepsi",
 4  "yearInvented": 1893
 5}
 6devnull {
 7  "name": "Coca-Cola",
 8  "yearInvented": 1886
 9}
10devnull {
11  "name": "Dr Pepper",
12  "yearInvented": 1885
13}
14devnull {
15  "name": "Hires Root Beer",
16  "yearInvented": 1876
17}
18devnull {
19  "name": "Vernors Ginger Ale",
20  "yearInvented": 1866
21}
22devnull {
23  "name": "Schweppes",
24  "yearInvented": 1783
25}