How to use the fluture.cache function in fluture

To help you get started, we’ve selected a few fluture 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 zerobias / telegram-mtproto / packages / telegram-mtproto / src / task / single-handler.js View on Github external
function fileMigrateHandler(uid, data, code, message, req, newDc) {
  req.dc = Just(newDc)

  // const futureAuth = Config.authRequest.get(uid, newDc)
  if (!alreadyMoved) {
    // Config.halt.set(uid, newDc, true)
    const auth = cache(
      moveAuthProgression(uid, newDc)
      //   .map(tapLog`after auth`)
      // .map(resp => (Config.halt.set(uid, newDc, false), resp))
      // .map(e => (log`auth`(e), e))
    )
    // const authReq = invoke(uid, 'auth.exportAuthorization', { dc_id: newDc })
    //   .map(resp => (console.log(resp), resp))
    //   // .map(({ id, bytes }) => ({ id, bytes }))
    //   // .map(tapLog`before auth`)
    //   .chain(resp => {
    //     const { id, bytes } = exportAuthRefine(resp)
    //     const refined = { id, bytes: [...bytes] }
    //     const futureAuth = Config.authRequest.get(uid, newDc)
    //     if (futureAuth) return futureAuth
    //     // const auth = cache(Auth(uid, newDc)
    //     //   .map(tapLog`after auth`)
github zerobias / telegram-mtproto / packages / telegram-mtproto / src / service / authorizer / index.js View on Github external
const req: typeof runThread = savedReq
    return req
  }

  const runThread = getUrl(uid, dc)
    .chain(url => authFuture(uid, dc, url))
    .map(res => ({ ...res, uid }))
    .chain(res => encaseP(async res => {
      const setter = Config.storageAdapter.set
      await setter.salt(uid, dc, res.serverSalt)
      await setter.authKey(uid, dc, res.authKey)
      await setter.authID(uid, dc, res.authKeyID)
      return res
    }, res))
    .map(res => (dispatch(MAIN.AUTH.RESOLVE(res), uid), res))
  const future = cache(runThread)
  Config.authRequest.set(uid, dc, future)
  return future
}
github zerobias / telegram-mtproto / packages / telegram-mtproto / src / plugins / long-poll.js View on Github external
get pending(): Promise {
    if (!this.currentRequest)
      this.currentRequest = cache(futureRequest(this.thread, this.maxWait)
        .map(x => {
          delete this.currentRequest
          this.thread.checkLongPoll()
          this.pending
        }))
    return this.currentRequest.promise()
  }