How to use the fluture.tryP 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 Bannerets / tdl / examples / using-fluture.js View on Github external
const { Client } = require('tdl')
const Future = require('fluture')

const client = new Client({
  apiId: 2222, // Your api_id
  apiHash: 'YOUR_API_HASH'
})

const searchChat = username =>
  client.invokeFuture({ _: 'searchPublicChat', username })
    .map(chat => `Chat: ${chat.title}, id: ${chat.id}`)
    .mapRej(err => `Error: ${err.message}`)

const login = Future.encaseP(client.login)

Future
  .tryP(client.connect)
  .chain(() => login(() => ({
    phoneNumber: 'YOUR_PHONE_NUMBER'
  })))
  .chain(() => searchChat('username'))
  .fork(console.error, console.log)
github Astrocoders / postgres-orm / src / PostgreSQLORM.ts View on Github external
const insert = (values: Payload) => {
    const query = generatePgInsert({ payload: values, table: tableName })

    return (
      Future.tryP(() => client.query(query.text, query.values))
        .map(debug ? R.tap(console.log) : R.identity)
        // @ts-ignore
        .map(value => new entityMapperClass(value.rows[0]))
    )
  }
github Astrocoders / postgres-orm / src / PostgreSQLORM.ts View on Github external
const find = (payload: Payload) => {
    const clause = getWhereClauseFromObject({ payload })

    return (
      Future.tryP(() =>
        client.query(`select * from ${tableName} ${clause.length !== 0 ? `where ${clause}` : ''}`),
      )
        .map(value => value.rows)
        // @ts-ignore
        .map(R.map(data => new entityMapperClass(data)))
    )
  }
github Astrocoders / postgres-orm / src / PostgreSQLORM.ts View on Github external
const requestRaw = (query: string): FutureInstance => {
    // @ts-ignore
    return Future.tryP(() => client.query(query)).pipe(mapResults)
  }
github mrosata / packt-mastering-fp / app / components / RemoteSlidesBtn.jsx View on Github external
function fetchSlides() {
  const url = 'http://beta.json-generator.com/api/json/get/VJihcRLIQ'
  return tryP(async function() {
    const res = await fetch(url)
    return res.json()
  })
}