How to use thunky - 4 common examples

To help you get started, we’ve selected a few thunky 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 cayasso / cacheman-mongo / lib / index.js View on Github external
{
              port: options.port || 27017,
              host: options.host || '127.0.0.1'
            }
          ]
          conn = uri.format(options)
        }
      } else {
        this.client = conn
      }
    }

    conn = conn || 'mongodb://127.0.0.1:27017'
    var coll = (this.coll = options.collection || 'cacheman')
    this.compression = options.compression || false
    this.ready = thunky((cb) => {
      function createIndex(err, db) {
        db.ensureIndex(coll, { expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => {
          cb(err, db)
        })
      }

      if ('string' === typeof conn) {
        const mongoOptions = OPTIONS_LIST.reduce((opt, key) => {
          delete opt[key]
          return opt
        }, Object.assign({}, options))

        MongoClient.connect(conn, mongoOptions, (err, db) => {
          if (err) return cb(err)
          createIndex(null, (this.client = db))
          db.ensureIndex(coll, { expireAt: 1 }, { expireAfterSeconds: 0 }, (err) => {
github arso-project / archipel / app / src / api / rpc.web.js View on Github external
export default function rpc () {
  const d = dnode()
  return thunky((cb) => {
    d.pipe(ws).pipe(d)
    d.on('remote', (remote) => cb(remote))
  })
}
github arso-project / archipel / packages / app / src / lib / rpc.js View on Github external
import hype from 'hyperpc'
import thunky from 'thunky'
import isElectron from 'is-electron-renderer'
import websocket from 'websocket-stream'
import { debugFactory } from './debug'

const debug = debugFactory('rpc')

const clientApi = {
  foo: (bar, cb) => cb(null, bar.toUpper() + ' from client!!')
}

const rpc = thunky((cb) => {
  if (isElectron) {
    import('electron').then(({ipcRenderer}) => {
      ipcRenderer.send('rpc')
      ipcRenderer.on('rpc', (ev, port) => {
        create('ws://localhost:' + port + '/rpc', cb)
      })
    })
  } else {
    create(window.location.origin.replace(/^http/, 'ws') + '/rpc', cb)
  }
})

function create (url, cb) {
  const ws = websocket(url)
  const rpc = hype(clientApi, {promise: true, debug: true})
github arso-project / archipel / app / src / api / rpc.electron.js View on Github external
export default function rpc () {
  const d = dnode()
  return thunky((cb) => {
    ipcRenderer.send('init')
    ipcRenderer.on('init', () => {
      d.on('remote', (remote) => cb(remote))
      d.on('data', (data) => ipcRenderer.send('dnode', data))
      ipcRenderer.on('dnode', (event, data) => {
        d.write(data)
      })
    })
  })
}

thunky

delay the evaluation of a paramless async function and cache the result

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis

Popular thunky functions