Skip to content

Commit

Permalink
test and support older versions of node
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-marcacci committed Jul 25, 2021
1 parent c3cdc2d commit 18f99e2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
container: "node:${{matrix.node}}"
strategy:
matrix:
node: ["16"]
node: ["12", "14", "16"]
services:
redis-single-instance:
image: redis
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
"prepare": "yarn build",
"prepublishOnly": "yarn install && yarn lint && yarn build && yarn test"
},
"dependencies": {},
"dependencies": {
"node-abort-controller": "^2.0.0"
},
"type": "module",
"exports": "./dist/index.js"
}
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { randomBytes, createHash } from "crypto";
import { EventEmitter } from "events";

// AbortController became available as a global in node version 16. Once version
// 14 reaches its end-of-life, this can be removed.
import PolyfillAbortController from "node-abort-controller";

import { Redis as IORedisClient } from "ioredis";
type Client = IORedisClient;

Expand Down Expand Up @@ -679,7 +683,11 @@ export default class Redlock extends EventEmitter {
// The AbortController/AbortSignal pattern allows the routine to be notified
// of a failure to extend the lock, and subsequent expiration. In the event
// of an abort, the error object will be made available at `signal.error`.
const controller = new AbortController();
const controller =
typeof AbortController === "undefined"
? new PolyfillAbortController()
: new AbortController();

const signal = controller.signal as RedlockAbortSignal;

function queue(): void {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"lib": ["es2020"],
"target": "es2020",
"target": "es2018",
"module": "es2020",
"outDir": "./dist",
"declaration": true,
Expand Down

0 comments on commit 18f99e2

Please sign in to comment.