How to use the sleep-promise function in sleep-promise

To help you get started, we’ve selected a few sleep-promise 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 celo-org / celo-monorepo / packages / celotool / src / lib / geth.ts View on Github external
resolve(receipt)
      },
      undefined,
      (error: any) => {
        logMessage.error = error
        exitTracerTool(logMessage)
      }
    )
  })

  const txReceipt: any = await transferToken
  const txHash = txReceipt ? txReceipt.transactionHash : ''

  // Need to wait for a bit to make sure that blockscout had enough time
  // to see the transaction and display it
  await sleep(BLOCKSCOUT_TIMEOUT)

  logMessage.txHash = txHash

  const handleError = (isError: boolean, data: { location: string; error: string }) => {
    if (isError) {
      exitTracerTool({ ...logMessage, ...data })
    }
  }

  validateTransactionAndReceipt(from, txReceipt!, handleError)
  await validateBlockscout(blockscoutUrl, txHash, from, handleError)
  await validateGethRPC(web3, txHash, from, handleError)
}
github celo-org / celo-monorepo / packages / celotool / src / cmds / bots / auto-verify.ts View on Github external
TIME_TO_WAIT_FOR_ATTESTATIONS_IN_MINUTES &&
    attestationsToComplete.length > 0
  ) {
    const messages = await fetchLatestMessagesFromToday(client, phoneNumber, 100)

    const res = await findValidCode(
      attestations,
      messages.map((_) => _.body),
      phoneNumber,
      attestationsToComplete,
      account
    )

    if (!res) {
      process.stdout.write('.')
      await sleep(POLLING_WAIT)
      continue
    }
    console.info('')

    logger.info(
      { waitingTime: moment.duration(moment().diff(startDate)).asSeconds() },
      'Received valid code'
    )

    const completeTx = await attestations.complete(phoneNumber, account, res.issuer, res.code)

    await completeTx.sendAndWaitForReceipt(txParams)

    logger.info({ issuer: res.issuer }, 'Completed attestation')
    attestationsToComplete = await attestations.getActionableAttestations(phoneNumber, account)
  }
github celo-org / celo-monorepo / packages / celotool / src / lib / geth.ts View on Github external
txResult,
          sendTransactionTime,
          baseLogMessage,
          blockscoutUrl,
          blockscoutMeasurePercent
        )
      })
      .catch((error: any) => {
        console.error('Load test transaction failed with error:', JSON.stringify(error))
        tracerLog({
          tag: LOG_TAG_TRANSACTION_ERROR,
          error: error.toString(),
          ...baseLogMessage,
        })
      })
    await sleep(txPeriodMs)
  }
}
github mvila / npm-addict / backend / fetcher.js View on Github external
if (!response.headers.has('X-RateLimit-Reset')) {
          this.app.log.warning(`Bad response from GitHub API while requesting '${url}' URL (HTTP status is 403 but 'X-RateLimit-Reset' header is missing)`);
          return undefined;
        }
        if (response.headers.get('X-RateLimit-Remaining') !== '0') {
          this.app.log.warning(`Bad response from GitHub API while requesting '${url}' URL (HTTP status is 403 but 'X-RateLimit-Remaining' header is ${response.headers.get('X-RateLimit-Remaining')})`);
          return undefined;
        }
        const resetTime = Number(response.headers.get('X-RateLimit-Reset')) * 1000;
        let waitTime = resetTime - Date.now() + 1000;
        if (waitTime <= 0) {
          this.app.log.debug(`Bad response from GitHub API while requesting '${url}' URL (HTTP status is 403 but 'X-RateLimit-Reset' is before current time)`);
          waitTime = 10000;
        }
        this.app.log.debug(`GitHub API limit reached, waiting ${waitTime / 1000} seconds...`);
        await sleep(waitTime);
      } else {
        this.app.log.warning(`Bad response from GitHub API while requesting '${url}' URL (HTTP status: ${response.status})`);
        return undefined;
      }
    }
  }
}
github celo-org / celo-monorepo / packages / celotool / src / lib / geth.ts View on Github external
const getFirstValidBlockscoutResponse = async (url: string, txHash: string) => {
  const attempts = MAXIMAL_BLOCKSCOUT_TIMEOUT / BLOCKSCOUT_FETCH_RETRY_TIME
  for (let attemptId = 0; attemptId < attempts; attemptId++) {
    const json = await fetchBlockscoutTxInfo(url, txHash)
    if (json.status !== '1') {
      await sleep(BLOCKSCOUT_FETCH_RETRY_TIME)
    } else {
      return [json, Date.now()]
    }
  }
  return [null, null]
}
github eropple / taskbotjs / example / src / jobs / FailJob.ts View on Github external
async perform(): Promise {
    const interval = Math.max(25, Math.round(chance.normal({mean: 300, dev: 250})));
    await sleepAsync(interval);
    throw new Error(`I failed after ${interval}ms.`);
  }
}
github zeit / now / packages / now-client / src / check-deployment-status.ts View on Github external
if (isFailed(deploymentUpdate) || aliasError) {
        debug(
          aliasError
            ? 'Alias assignment error has occurred'
            : 'Deployment has failed'
        );
        return yield {
          type: 'error',
          payload: aliasError
            ? deploymentUpdate.aliasError
            : deploymentUpdate.error || deploymentUpdate,
        };
      }
    }

    await sleep(ms('1.5s'));
  }
}
github eropple / taskbotjs / service / src / util / index.ts View on Github external
export async function sleepFor(p: TimeInterval): Promise {
  return sleepAsync(intervalSplayDuration(p.interval, p.splay).shiftTo("seconds").seconds);
}
github ricohr / ricoh-r-console / src / data / MtpActionCreator.jsx View on Github external
applyPropValues(propValues) {
    const ps = Object.keys(propValues).map(name=>{
            return this.mtpDevice.setPropValue(name, propValues[name])
          });
    return Promise.all(ps).then(Sleep(1000)).then(()=>{
      return this.loadProperties();
    });
  }

sleep-promise

Resolves a promise after a specified delay

MIT
Latest version published 4 years ago

Package Health Score

60 / 100
Full package analysis

Popular sleep-promise functions