Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Node 6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly committed Nov 20, 2019
1 parent 96f0352 commit a351318
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
11 changes: 11 additions & 0 deletions test/async_utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

// Converts a function that takes a Node-style callback (err, result) as its last argument into a
// function that returns a Promise. This is equivalent to util.promisify, but is reimplemented here
// because promisify isn't supported in Node 6.
// Usage: await asyncifyNode(doSomething)(allParamsExceptCallback)
function promisify(f) {
return (...args) =>
new Promise((resolve, reject) =>
f(...args, (err, result) => err ? reject(err) : resolve(result)));
}

// Converts a function that takes a single-parameter callback (like most SDK methods) into a Promise.
// This is different from util.promisify, which uses Node-style callbacks with two parameters.
// Usage: await asyncify(callback => doSomething(params, callback))
Expand Down Expand Up @@ -83,6 +93,7 @@ function AsyncQueue() {

module.exports = {
asyncify,
promisify,
sleepAsync,
withCloseable,
AsyncQueue,
Expand Down
3 changes: 1 addition & 2 deletions test/file_data_source-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const fs = require('fs');
const tmp = require('tmp');
const { promisify } = require('util');
const dataKind = require('../versioned_data_kind');
const { asyncify, sleepAsync } = require('./async_utils');
const { asyncify, promisify, sleepAsync } = require('./async_utils');
const { stubLogger } = require('./stubs');

const LaunchDarkly = require('../index');
Expand Down
3 changes: 1 addition & 2 deletions test/polling-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { promisify } = require('util');
const InMemoryFeatureStore = require('../feature_store');
const PollingProcessor = require('../polling');
const dataKind = require('../versioned_data_kind');
const { asyncify, sleepAsync } = require('./async_utils');
const { asyncify, promisify, sleepAsync } = require('./async_utils');
const stubs = require('./stubs');

describe('PollingProcessor', () => {
Expand Down
3 changes: 1 addition & 2 deletions test/requestor-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { promisify } from 'util';
import Requestor from '../requestor';
import * as dataKind from '../versioned_data_kind';
import { withCloseable } from './async_utils';
import { promisify, withCloseable } from './async_utils';
import { createServer, respond, respondJson } from './http_server';

describe('Requestor', () => {
Expand Down

0 comments on commit a351318

Please sign in to comment.