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 1e03855
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 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"
}
9 changes: 8 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,10 @@ 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 = AbortController
? new AbortController()
: new PolyfillAbortController();

const signal = controller.signal as RedlockAbortSignal;

function queue(): void {
Expand Down

0 comments on commit 1e03855

Please sign in to comment.