How to use thenify - 10 common examples

To help you get started, we’ve selected a few thenify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-server / source / base_server.ts View on Github external
// xx response.serviceDiagnostics.push( new DiagnosticInfo({ additionalInfo: messages.join("\n")}));

    assert(_.isArray(messages));
    assert(typeof messages[0] === "string");

    response.responseHeader.stringTable = messages;
    // tslint:disable:no-console
    console.log(chalk.cyan(" messages "), messages.join("\n"));
    return response;
}

// tslint:disable:no-var-requires
const thenify = require("thenify");
const opts = { multiArgs: false };
OPCUABaseServer.prototype.resumeEndPoints = thenify.withCallback(OPCUABaseServer.prototype.resumeEndPoints, opts);
OPCUABaseServer.prototype.suspendEndPoints = thenify.withCallback(OPCUABaseServer.prototype.suspendEndPoints, opts);
OPCUABaseServer.prototype.suspendEndPoints = thenify.withCallback(OPCUABaseServer.prototype.suspendEndPoints, opts);
github node-opcua / node-opcua / packages / node-opcua-client / src / client_base.js View on Github external
console.log("        .initialDelay........... ", this.connectionStrategy.initialDelay);
    console.log("        .maxDelay............... ", this.connectionStrategy.maxDelay);
    console.log("        .randomisationFactor.... ", this.connectionStrategy.randomisationFactor);
    console.log("  keepSessionAlive.............. ", this.keepSessionAlive);
};

exports.OPCUAClientBase = OPCUAClientBase;

const thenify = require("thenify");
/**
 * @method connect
 * @param endpointUrl {string}
 * @async
 * @return {Promise}
 */
OPCUAClientBase.prototype.connect = thenify.withCallback(OPCUAClientBase.prototype.connect);
OPCUAClientBase.prototype.disconnect = thenify.withCallback(OPCUAClientBase.prototype.disconnect);
OPCUAClientBase.prototype.getEndpoints = thenify.withCallback(OPCUAClientBase.prototype.getEndpoints);
OPCUAClientBase.prototype.findServers = thenify.withCallback(OPCUAClientBase.prototype.findServers);
OPCUAClientBase.prototype.findServersOnNetwork = thenify.withCallback(OPCUAClientBase.prototype.findServersOnNetwork);
// deprecated:
OPCUAClientBase.prototype.getEndpointsRequest = thenify.withCallback(OPCUAClientBase.prototype.getEndpointsRequest);
github ShieldBattery / ShieldBattery / server / lib / file-upload / local-filesystem.js View on Github external
import config from '../../config'
import fs from 'fs'
import koaMount from 'koa-mount'
import koaStatic from 'koa-static'
import log from '../logging/logger.js'
import path from 'path'
import thenify from 'thenify'
import util from 'util'

// How long browsers can cache resources for (in milliseconds). These resources should all be pretty
// static, so this can be a long time
const FILE_MAX_AGE_MS = 14 * 24 * 60 * 60 * 1000

const access = thenify(fs.access)
const mkdir = thenify(fs.mkdir)
const unlinkAsync = util.promisify(fs.unlink)

async function createDirectory(path) {
  try {
    await access(path)
  } catch (_) {
    await mkdir(path)
  }
}

async function createDirTree(dir) {
  const segments = dir.split(path.sep)
  let currentDir = ''
  for (const segment of segments) {
    currentDir += segment + path.sep
github skale-me / skale / lib / dataset.js View on Github external
Dataset.prototype.values = function () {return this.map(a => a[1]);};

Dataset.prototype.lookup = thenify(function (key, done) {
  return this.filter((kv, args) => kv[0] === args.key, {key})
    .map(kv => kv[1])
    .collect(done);
});

Dataset.prototype.countByValue = thenify(function (done) {
  return this.map(e => [e, 1])
    .reduceByKey((a, b) => a + b, 0)
    .collect(done);
});

Dataset.prototype.countByKey = thenify(function (done) {
  return this.mapValues(function () {return 1;})
    .reduceByKey((a, b) => a + b, 0)
    .collect(done);
});

Dataset.prototype.collect = thenify(function (done) {
  return this.aggregate((a, b) => {a.push(b); return a;}, (a, b) => a.concat(b), [], done);
});

// The stream action allows the master to return a dataset as a stream
// Each worker spills its partitions to disk
// then master pipes each remote partition into output stream
Dataset.prototype.stream = function (options = {}) {
  const self = this;
  const outStream = merge2();
  const opt = {
github ShieldBattery / ShieldBattery / client / active-game / active-game-manager.js View on Github external
const injectPath = path.resolve(remote.app.getAppPath(), '../game/dist/shieldbattery.dll')

const statAsync = thenify(fs.stat)
const unlinkAsync = thenify(fs.unlink)
async function removeIfOld(path, maxAge) {
  try {
    const stat = await statAsync(path)
    if (Date.now() - stat.mtime > maxAge) {
      await unlinkAsync(path)
    }
  } catch (e) {
    // We won't care the file doesn't exist/can't be touched
  }
}

const accessAsync = thenify(fs.access)
async function doLaunch(gameId, serverPort, settings) {
  try {
    await accessAsync(injectPath)
  } catch (err) {
    throw new Error(`Could not access/find shieldbattery dll at ${injectPath}`)
  }

  const { starcraftPath } = settings.local
  if (!starcraftPath) {
    throw new Error('No Starcraft path set')
  }
  const downgradePath = getDowngradePath()
  const checkResult = await checkStarcraftPath(starcraftPath, downgradePath)
  if (!checkResult.path || !checkResult.version) {
    throw new Error(
      `StarCraft path [${starcraftPath}, ${downgradePath}] not valid: ` +
github chentsulin / koa-graphql / src / __tests__ / helpers / koa-multer.js View on Github external
return async function(ctx, next) {
      const thenified = thenify(_single(param));
      await thenified(ctx.req, ctx.res);
      await next();
    };
  };
github node-opcua / node-opcua / packages / node-opcua-client-proxy / src / proxy.js View on Github external
Object.defineProperty(proxyObject, "__monitoredItem_execution_flag", {value: monitoredItem, enumerable: false});

    proxyObject.__monitoredItem_execution_flag.on("changed", function (dataValue) {
        proxyObject.executableFlag = dataValue.value.value;
        //xx console.log(" execution flag = ", proxyObject.executableFlag , proxyObject.browseName , proxyObject.nodeId.toString());
        //xx proxyObject.emit("execution_flag_changed",proxyObject.executableFlag);
    });
};

exports.UAProxyManager = UAProxyManager;

const thenify = require("thenify");
UAProxyManager.prototype.start = thenify.withCallback(UAProxyManager.prototype.start);
UAProxyManager.prototype.stop = thenify.withCallback(UAProxyManager.prototype.stop);

UAProxyManager.prototype.getObject = thenify.withCallback(UAProxyManager.prototype.getObject);
ProxyBaseNode.prototype.readValue  = thenify.withCallback(ProxyBaseNode.prototype.readValue);
ProxyBaseNode.prototype.writeValue = thenify.withCallback(ProxyBaseNode.prototype.writeValue);
github node-opcua / node-opcua / packages / node-opcua-client / src / opcua_client.js View on Github external
* @param userIdentityInfo
 * @return {Promise}
 * @async
 */
OPCUAClient.prototype.changeSessionIdentity = thenify.withCallback(OPCUAClient.prototype.changeSessionIdentity);
/**
 * @method closeSession
 * @param session {ClientSession}
 * @param deleteSubscriptions  {Boolean} - whether to delete
 * @return {Promise}
 * @async
 * @example
 *    const session  = await client.createSession();
 *    await client.closeSession(session);
 */
OPCUAClient.prototype.closeSession = thenify.withCallback(OPCUAClient.prototype.closeSession);


const ClientSubscription = require("./client_subscription").ClientSubscription;
OPCUAClient.prototype.withSubscription = function (endpointUrl, subscriptionParameters, innerFunc, callback) {

    assert(_.isFunction(innerFunc));
    assert(_.isFunction(callback));

    this.withSession(endpointUrl, function (session, done) {
        assert(_.isFunction(done));

        const subscription = new ClientSubscription(session, subscriptionParameters);

        try {
            innerFunc(session, subscription, function () {
github node-opcua / node-opcua / packages / node-opcua-client / src / client_session.js View on Github external
exports.ClientSession = ClientSession;



const thenify = require("thenify");
const opts = { multiArgs : false };
ClientSession.prototype.browse                = thenify.withCallback(ClientSession.prototype.browse,opts);
ClientSession.prototype.readVariableValue     = thenify.withCallback(ClientSession.prototype.readVariableValue,opts);
ClientSession.prototype.readHistoryValue      = thenify.withCallback(ClientSession.prototype.readHistoryValue,opts);
ClientSession.prototype.write                 = thenify.withCallback(ClientSession.prototype.write,opts);
ClientSession.prototype.writeSingleNode       = thenify.withCallback(ClientSession.prototype.writeSingleNode,opts);
ClientSession.prototype.readAllAttributes     = thenify.withCallback(ClientSession.prototype.readAllAttributes,opts);
ClientSession.prototype.read                  = thenify.withCallback(ClientSession.prototype.read,opts);
ClientSession.prototype.createSubscription    = thenify.withCallback(ClientSession.prototype.createSubscription,opts);
ClientSession.prototype.deleteSubscriptions   = thenify.withCallback(ClientSession.prototype.deleteSubscriptions,opts);
ClientSession.prototype.transferSubscriptions = thenify.withCallback(ClientSession.prototype.transferSubscriptions,opts);
ClientSession.prototype.createMonitoredItems  = thenify.withCallback(ClientSession.prototype.createMonitoredItems,opts);
ClientSession.prototype.modifyMonitoredItems  = thenify.withCallback(ClientSession.prototype.modifyMonitoredItems,opts);
ClientSession.prototype.modifySubscription    = thenify.withCallback(ClientSession.prototype.modifySubscription,opts);
ClientSession.prototype.setMonitoringMode     = thenify.withCallback(ClientSession.prototype.setMonitoringMode,opts);
ClientSession.prototype.publish               = thenify.withCallback(ClientSession.prototype.publish,opts);
ClientSession.prototype.republish             = thenify.withCallback(ClientSession.prototype.republish,opts);
ClientSession.prototype.deleteMonitoredItems  = thenify.withCallback(ClientSession.prototype.deleteMonitoredItems,opts);
ClientSession.prototype.setPublishingMode     = thenify.withCallback(ClientSession.prototype.setPublishingMode,opts);
ClientSession.prototype.translateBrowsePath   = thenify.withCallback(ClientSession.prototype.translateBrowsePath,opts);
ClientSession.prototype.performMessageTransaction= thenify.withCallback(ClientSession.prototype.performMessageTransaction,opts);
ClientSession.prototype.close                 = thenify.withCallback(ClientSession.prototype.close,opts);
ClientSession.prototype.call                  = thenify.withCallback(ClientSession.prototype.call,opts);
ClientSession.prototype.getMonitoredItems     = thenify.withCallback(ClientSession.prototype.getMonitoredItems,opts);
ClientSession.prototype.getArgumentDefinition = thenify.withCallback(ClientSession.prototype.getArgumentDefinition,opts);
github skale-me / skale / lib / client.js View on Github external
this.output.write(msg);
  } catch(err) {
    throw new Error('send error');
  }
});

Client.prototype.devices = thenify(function (o, callback) {
  var self = this;
  this.send(0, {cmd: 'devices', data: {query: o}}, function (err, dev) {
    for (var i in dev)
      self.hostId[dev[i].uuid] = dev[i].id;
    callback(err, dev);
  });
});

Client.prototype.get = thenify(function (uuid, callback) {
  this.send(0, {cmd: 'get', data: uuid}, callback);
});

Client.prototype.notify = function (uuid) {
  this.output.write({cmd: 'notify', data: uuid});
};

Client.prototype.subscribe = function (topic) {
  this.output.write({cmd: 'subscribe', data: topic});
  return this;
};

Client.prototype.unsubscribe = function (topic) {
  this.output.write({cmd: 'unsubscribe', data: topic});
};

thenify

Promisify a callback-based function

MIT
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis

Popular thenify functions