mirror of https://github.com/grpc/grpc-node.git
Merge pull request #2838 from murgatroid99/grpc-js_node_12_fix
grpc-js: Use util.promisify instead of fs/promises for Node 12 compatibility
This commit is contained in:
commit
0e39b261b1
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@grpc/grpc-js",
|
"name": "@grpc/grpc-js",
|
||||||
"version": "1.12.1",
|
"version": "1.12.2",
|
||||||
"description": "gRPC Library for Node - pure JS implementation",
|
"description": "gRPC Library for Node - pure JS implementation",
|
||||||
"homepage": "https://grpc.io/",
|
"homepage": "https://grpc.io/",
|
||||||
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
|
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
|
||||||
|
|
|
@ -15,9 +15,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs/promises';
|
import * as fs from 'fs';
|
||||||
import * as logging from './logging';
|
import * as logging from './logging';
|
||||||
import { LogVerbosity } from './constants';
|
import { LogVerbosity } from './constants';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
|
||||||
const TRACER_NAME = 'certificate_provider';
|
const TRACER_NAME = 'certificate_provider';
|
||||||
|
|
||||||
|
@ -56,6 +57,8 @@ export interface FileWatcherCertificateProviderConfig {
|
||||||
refreshIntervalMs: number;
|
refreshIntervalMs: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const readFilePromise = promisify(fs.readFile);
|
||||||
|
|
||||||
export class FileWatcherCertificateProvider implements CertificateProvider {
|
export class FileWatcherCertificateProvider implements CertificateProvider {
|
||||||
private refreshTimer: NodeJS.Timeout | null = null;
|
private refreshTimer: NodeJS.Timeout | null = null;
|
||||||
private fileResultPromise: Promise<[PromiseSettledResult<Buffer>, PromiseSettledResult<Buffer>, PromiseSettledResult<Buffer>]> | null = null;
|
private fileResultPromise: Promise<[PromiseSettledResult<Buffer>, PromiseSettledResult<Buffer>, PromiseSettledResult<Buffer>]> | null = null;
|
||||||
|
@ -82,9 +85,9 @@ export class FileWatcherCertificateProvider implements CertificateProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.fileResultPromise = Promise.allSettled([
|
this.fileResultPromise = Promise.allSettled([
|
||||||
this.config.certificateFile ? fs.readFile(this.config.certificateFile) : Promise.reject<Buffer>(),
|
this.config.certificateFile ? readFilePromise(this.config.certificateFile) : Promise.reject<Buffer>(),
|
||||||
this.config.privateKeyFile ? fs.readFile(this.config.privateKeyFile) : Promise.reject<Buffer>(),
|
this.config.privateKeyFile ? readFilePromise(this.config.privateKeyFile) : Promise.reject<Buffer>(),
|
||||||
this.config.caCertificateFile ? fs.readFile(this.config.caCertificateFile) : Promise.reject<Buffer>()
|
this.config.caCertificateFile ? readFilePromise(this.config.caCertificateFile) : Promise.reject<Buffer>()
|
||||||
]);
|
]);
|
||||||
this.fileResultPromise.then(([certificateResult, privateKeyResult, caCertificateResult]) => {
|
this.fileResultPromise.then(([certificateResult, privateKeyResult, caCertificateResult]) => {
|
||||||
if (!this.refreshTimer) {
|
if (!this.refreshTimer) {
|
||||||
|
|
Loading…
Reference in New Issue