forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#182] Support gRPC stream flowable
[pinpoint-apm#177] Update minimum NodeJS version to Node@16
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Pinpoint Node.js Agent | ||
* Copyright 2021-present NAVER Corp. | ||
* Apache License v2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const { Readable } = require('node:stream') | ||
|
||
class BoundedBufferReadableStream { | ||
constructor(constructorOptions) { | ||
this.buffer = [] | ||
this.stopped = false | ||
|
||
const options = constructorOptions || {} | ||
this.readable = new Readable(Object.assign({ | ||
read() { | ||
this.stopped = false | ||
this.readStart() | ||
} | ||
}, options)) | ||
} | ||
|
||
push(data) { | ||
if (!data) { | ||
return | ||
} | ||
|
||
this.buffer.push(data) | ||
this.readStart() | ||
} | ||
|
||
end() { | ||
this.readable.end() | ||
} | ||
|
||
readStart() { | ||
if (this.stopped) { | ||
return | ||
} | ||
|
||
const length = this.buffer.length | ||
for (let index = 0; index < length; index++) { | ||
if (this.readable.push(this.buffer.shift())) { | ||
this.stopped = true | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = BoundedBufferReadableStream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Pinpoint Node.js Agent | ||
* Copyright 2020-present NAVER Corp. | ||
* Apache License v2.0 | ||
*/ | ||
|
||
const test = require('tape') | ||
|