How to use the @dfuse/client.waitFor function in @dfuse/client

To help you get started, we’ve selected a few @dfuse/client 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 dfuse-io / client-js / examples / advanced / track-ram-usage.ts View on Github external
* might come in the future. This means that even if there is less
       * results than expected per page, future blocks might add more
       * results, hence the `cursor` not returning as empty.
       *
       * **Note** Doing a descending search will yield an empty
       * string cursor at some point because you will reach the Genesis
       * Block of the chain (Block #1).
       */
      if (page.cursor === "" || page.transactions.length < resultPerPage) {
        // No more pages, stop page fetch
        break
      }

      console.log(`RAM Running Total (${resultCount} transactions included) is ${runningTotal}`)
      console.log(`Fetching next page (#${pageCount + 1}) in 5s ...`)
      await waitFor(5000)
    }

    console.log(`Running total is ${runningTotal}`)
    console.log(`Completed after reading ${pageCount} page(s)`)
  } catch (error) {
    console.log("An error occurred", error)
  }

  client.release()
}
github dfuse-io / client-js / examples / advanced / client-and-socket-notifications.ts View on Github external
if (message.type === InboundMessageType.HEAD_INFO) {
      console.log("WebSocket stream data.", JSON.stringify(message.data))

      // Mark latest location where we want to start back at
      wsStream.mark({ atBlockNum: message.data.head_block_num })
    }
  })

  wsStream.onPostRestart = () => {
    console.log()
    console.log(
      "<============= WebSocket stream has restarted to its previous `mark()` location =============>"
    )
  }

  await waitFor(35000)
  await graphqlStream.close()
  await wsStream.close()

  client.release()
}
github dfuse-io / client-js / examples / advanced / multiple-active-streams.ts View on Github external
})
  )

  const ramData = { accounts: "eosio.token", action_names: "transfer", receivers: "eosio.ram" }
  const ramStream: Stream = await client.streamActionTraces(
    ramData,
    dynamicMessageDispatcher({
      listening: onListeningFactory("ram_transfer"),
      action_trace: onTransferToEosioRamAction
    })
  )

  console.log(
    "Notice how `Buy RAM` and `RAM cost` happens in random order, due to using 2 independent streams."
  )
  await waitFor(60000)
  await buyRamStream.close()
  await ramStream.close()

  console.log("")

  const mergedData = {
    accounts: "eosio|eosio.token",
    action_names: "buyrambytes|transfer",
    receivers: "eosio|eosio.token|eosio.ram"
  }
  const mergedStream: Stream = await client.streamActionTraces(
    mergedData,
    dynamicMessageDispatcher({
      listening: onListeningFactory("merged"),
      action_trace: onMergedAction
    })
github dfuse-io / client-js / examples / basic / stream-global-state.ts View on Github external
const stream = await client.streamTableRows(
    { code: "eosio", scope: "eosio", table: "global" },
    (message: InboundMessage) => {
      if (message.type === InboundMessageType.TABLE_DELTA) {
        const { dbop, block_num } = message.data as TableDeltaData
        const { total_ram_stake, total_unpaid_blocks } = dbop.new!.json!

        console.log(
          `Global state change @ #${block_num} [Total RAM Stake ${total_ram_stake}, Total Unpaid Block Count ${total_unpaid_blocks}]`
        )
      }
    }
  )

  await waitFor(5000)
  await stream.close()

  client.release()
}
github dfuse-io / client-js / examples / reference / stream-transaction.ts View on Github external
return
      }

      if (message.type === InboundMessageType.TRANSACTION_LIFECYCLE) {
        console.log(prettifyJson(message.data))
        return
      }

      if (message.type === InboundMessageType.ERROR) {
        console.log(prettifyJson(message.data))
        return
      }
    }
  )

  await waitFor(5000)
  await stream.close()

  client.release()
}
github dfuse-io / client-js / examples / advanced / nodejs-fetch-and-websocket-options.ts View on Github external
const onMessage = (message: InboundMessage) => {
    if (message.type === InboundMessageType.LISTENING) {
      console.log("Stream is now listening.")
    }
  }

  const stream = await client.streamActionTraces(
    {
      accounts: "eosio.token",
      action_names: "issue"
    },
    onMessage
  )

  console.log("Socket is now connected.")
  await waitFor(35000)
  await stream.close()

  client.release()
}
github dfuse-io / client-js / examples / reference / stream-table-rows.ts View on Github external
}

      if (message.type === InboundMessageType.TABLE_DELTA) {
        console.log(prettifyJson(message.data))
        return
      }

      if (message.type === InboundMessageType.ERROR) {
        console.log(prettifyJson(message.data))
        return
      }
    },
    { fetch: true }
  )

  await waitFor(15000)
  await stream.close()

  client.release()
}
github dfuse-io / client-js / examples / advanced / never-miss-a-beat.ts View on Github external
async function main() {
  const client = createDfuseClient({
    apiKey: DFUSE_API_KEY,
    network: DFUSE_API_NETWORK,
    streamClientOptions: {
      socketOptions: {
        reconnectDelayInMs: 250
      }
    }
  })

  const engine = new Engine(client)
  await engine.start()

  await waitFor(50000)
  await engine.stop()

  client.release()
}
github dfuse-io / client-js / examples / advanced / stream-only-irreversible-events.ts View on Github external
network: DFUSE_API_NETWORK
  })

  const stream = await client.streamActionTraces(
    { accounts: "eosio.token", action_names: "transfer" },
    onMessage,
    {
      /**
       * Request to only obtain irreversible notifications by specifying this
       * common flag and setting its value to true.
       */
      irreversible_only: true
    }
  )

  await waitFor(5000)
  await stream.close()

  client.release()
}
github dfuse-io / client-js / examples / advanced / navigating-forks.ts View on Github external
async function main() {
  const client = createDfuseClient({
    apiKey: DFUSE_API_KEY,
    network: DFUSE_API_NETWORK
  })

  const engine = new Engine(client)
  await engine.start()

  await waitFor(50000)
  await engine.stop()

  client.release()
}