Skip to content

Commit

Permalink
[pinpoint-apm#182] Support gRPC stream flowable
Browse files Browse the repository at this point in the history
[pinpoint-apm#177] Update minimum NodeJS version to Node@16
  • Loading branch information
feelform committed Mar 21, 2024
1 parent 719afa7 commit 1b7406d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
53 changes: 53 additions & 0 deletions lib/client/bounded-buffer-readable-stream.js
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pinpoint-node-agent",
"version": "0.9.0-next.4",
"version": "1.0.0-next.1",
"main": "index.js",
"types": "index.d.ts",
"type": "commonjs",
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/pinpoint-apm/pinpoint-node-agent",
"engines": {
"node": ">=14.0"
"node": ">=16.0"
},
"keywords": [
"pinpoint",
Expand Down
8 changes: 8 additions & 0 deletions test/client/bounded-buffer-readable-stream.test.js
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')

0 comments on commit 1b7406d

Please sign in to comment.