How to use thunkify - 5 common examples

To help you get started, we’ve selected a few thunkify 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 pavelvlasov / koa-generic-session-mongo / src / store.js View on Github external
*set(sid, sess, ttl) {
    // clone original sess
    sess = {...sess};
    const maxAge = sess.cookie && (sess.cookie.maxAge || sess.cookie.maxage);
    const col = yield this.col;
    const update = thunkify(col.update.bind(col));

    sess.sid = sid;
    sess.ttl = new Date((ttl || ('number' == typeof maxAge
      ? maxAge : ONE_DAY)) + Date.now());

    return yield update({sid: sid}, sess, {upsert: true});
  }
github robin98sun / koa-jwt-redis-session / src / index.js View on Github external
debug('Redis options:', redisOptions);

        const db = redisOptions.db || 0
        const ttl = this.ttl = redisOptions.ttl || expiresIn || EXPIRES_IN_SECONDS

        //redis client for session
        this.client = new redis(redisOptions)

        const client = this.client;

        client.select(db, function () {
            debug('redis changed to db %d', db);
        });

        client.get = thunkify(client.get);
        client.exists = thunkify(client.exists);
        client.ttl = ttl ? (key)=>{ client.expire(key, ttl); } : ()=>{};

        client.on('connect', function () {
            debug('redis is connecting');
        });

        client.on('ready', function () {
            debug('redis ready');
        });

        client.on('reconnect', function () {
            debug('redis is reconnecting');
        });

        client.on('error', function (err) {
            debug('redis encouters error: %j', err.stack || err);
github pavelvlasov / koa-generic-session-mongo / src / store.js View on Github external
*get(sid) {
    const col = yield this.col;
    const findOne = thunkify(col.findOne.bind(col));

    return yield findOne({sid: sid}, {_id: 0, ttl: 0, sid: 0});
  }
github robin98sun / koa-jwt-redis-session / src / index.js View on Github external
let redisOptions = opts || {}
        debug('Redis options:', redisOptions);

        const db = redisOptions.db || 0
        const ttl = this.ttl = redisOptions.ttl || expiresIn || EXPIRES_IN_SECONDS

        //redis client for session
        this.client = new redis(redisOptions)

        const client = this.client;

        client.select(db, function () {
            debug('redis changed to db %d', db);
        });

        client.get = thunkify(client.get);
        client.exists = thunkify(client.exists);
        client.ttl = ttl ? (key)=>{ client.expire(key, ttl); } : ()=>{};

        client.on('connect', function () {
            debug('redis is connecting');
        });

        client.on('ready', function () {
            debug('redis ready');
        });

        client.on('reconnect', function () {
            debug('redis is reconnecting');
        });

        client.on('error', function (err) {
github pavelvlasov / koa-generic-session-mongo / src / store.js View on Github external
*destroy(sid) {
    const col = yield this.col;
    const remove = thunkify(col.remove.bind(col));

    yield remove({sid: sid});
  }
}

thunkify

Turn callbacks, arrays, generators, generator functions, and promises into a thunk

MIT
Latest version published 10 years ago

Package Health Score

53 / 100
Full package analysis

Popular thunkify functions