How to use the js-data.utils.Promise function in js-data

To help you get started, we’ve selected a few js-data 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 js-data / js-data-mongodb / src / index.js View on Github external
* @default {}
   */
  this.updateOpts || (this.updateOpts = {})
  utils.fillIn(this.updateOpts, UPDATE_OPTS_DEFAULTS)

  /**
   * Default options to pass to collection#destroy.
   *
   * @name MongoDBAdapter#removeOpts
   * @type {object}
   * @default {}
   */
  this.removeOpts || (this.removeOpts = {})
  utils.fillIn(this.removeOpts, REMOVE_OPTS_DEFAULTS)

  this.client = new utils.Promise((resolve, reject) => {
    MongoClient.connect(opts.uri, opts.mongoDriverOpts, (err, client) => {
      if (err) {
        return reject(err)
      }
      this._db = client.db()
      resolve(this._db)
    })
  })
}
github js-data / js-data-firebase / src / index.js View on Github external
function createTask (fn) {
  return new utils.Promise(fn).then((result) => {
    taskInProcess = false
    queue.shift()
    setTimeout(dequeue, 0)
    return result
  }, (err) => {
    taskInProcess = false
    queue.shift()
    setTimeout(dequeue, 0)
    return utils.reject(err)
  })
}