How to use delay - 10 common examples

To help you get started, we’ve selected a few delay 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 semantic-release / npm / test / helpers / npm-registry.js View on Github external
async function start() {
  await getStream(await docker.pull(IMAGE));

  container = await docker.createContainer({
    Tty: true,
    Image: IMAGE,
    PortBindings: {[`${COUCHDB_PORT}/tcp`]: [{HostPort: `${SERVER_PORT}`}]},
    Env: [`COUCHDB_USER=${COUCHDB_USER}`, `COUCHDB_PASSWORD=${COUCHDB_PASSWORD}`],
  });

  await container.start();
  await delay(4000);

  try {
    // Wait for the registry to be ready
    await pRetry(() => got(`http://${SERVER_HOST}:${SERVER_PORT}/registry/_design/app`, {cache: false}), {
      retries: 7,
      minTimeout: 1000,
      factor: 2,
    });
  } catch (_) {
    throw new Error(`Couldn't start npm-docker-couchdb after 2 min`);
  }

  // Create user
  await got(`http://${SERVER_HOST}:${SERVER_PORT}/_users/org.couchdb.user:${NPM_USERNAME}`, {
    json: true,
    auth: `${COUCHDB_USER}:${COUCHDB_PASSWORD}`,
github Yoctol / bottender / src / plugins / withTyping.js View on Github external
const delay =
          methodOptions &&
          typeof methodOptions === 'object' &&
          typeof methodOptions.delay === 'number'
            ? methodOptions.delay
            : options.delay;

        if (methodOptions) {
          args[len - 1] = omit(methodOptions, ['delay']);
        }

        if (this.typingOn) {
          await this.typingOn();
        }

        await sleep(delay);

        return _method.call(context, ...args);
      };
      /* eslint-enable func-names */
github inker / draw / src / model / fetch-parse-pots.ts View on Github external
export async function tryFetch(url: string) {
  while (!navigator.onLine) {
    console.error("you're offline, retrying...")
    await delay(1000)
  }
  const response = await fetch(proxify(url, 'latin1'))
  if (response.status !== 200) {
    throw new Error(`${url}: ${response.status}`)
  }
  const text = await response.text()
  if (text.includes('<title>404 Not Found</title>')) {
    // stupid me
    throw new Error(`${url}: 404`)
  }
  return text
}
github inker / draw / src / model / fetchPotsData.ts View on Github external
async function tryFetch(url: string) {
  while (!navigator.onLine) {
    console.error("you're offline, retrying...")
    await delay(1000)
  }
  const text = await proxy(url, 'latin1')
  if (text.includes('<title>404 Not Found</title>')) {
    // stupid me
    throw new Error(`${url}: 404`)
  }
  return text
}
github inker / draw / src / routes / Pages / index.tsx View on Github external
// stage,
        season,
      })

      setPopup({
        waiting: false,
        error: null,
      })
    } catch (err) {
      console.error(err)
      setPopup({
        waiting: false,
        error: 'Could not fetch data',
      })

      await delay(1000)
      const {
        tournament: newTournament,
        stage: newStage,
      } = params

      const newSeason = pots && season !== currentSeasonByTournament(newTournament, newStage)
        ? season
        : undefined
      onSeasonChange(newTournament, newStage, newSeason)
      setPopup({
        error: null,
      })
    }
  }
github mizchi / next-editor / src / ui / components / utils / Initializer.tsx View on Github external
async componentDidMount() {
      // UI Boot
      await delay(150)
      const { isFirstVisit, ...actions } = this.props

      if (isFirstVisit) {
        // Start omotenashi
        // Remove first visit flag
        await actions.setConfigValue({ key: "isFirstVisit", value: false })

        // Open scratch.md as user first view
        actions.loadFile({ filepath: "/playground/scratch.md" })

        // TODO: Reload git on init. Sometimes initialze on git is failing
        await delay(300)
        actions.initializeGitStatus("/playground")
      }

      // TODO: dirty hack to focus
      // Focus first element
      await delay(150)
      const target = (document as any).querySelector("textarea")
      target && target.focus()
    }
  })
github alexcroox / jira-timer-menubar / main.js View on Github external
app.on('ready', async () => {

  // transparency workaround https://github.com/electron/electron/issues/2170
  await delay(10)

  mb = menubar({
    alwaysOnTop: process.env.NODE_ENV === 'development',
    icon: path.join(app.getAppPath(), '/static/tray.png'),
    width: 500,
    minWidth: 500,
    maxWidth: 500,
    minHeight: 530,
    hasShadow: false,
    preloadWindow: true,
    resizable: true,
    transparent: true,
    frame: false,
    toolbar: false
  })
github saltyshiomix / react-ssr / packages / express-engine-jsx / src / bin / react-ssr-dev.ts View on Github external
async function dev() {
  let proc;
  const wrapper = () => {
    if (proc) {
      proc.kill();
    }
  };
  process.on('SIGINT', wrapper);
  process.on('SIGTERM', wrapper);
  process.on('exit', wrapper);

  proc = serve(server, false);

  await delay(300);

  // const app = module.exports.__REACT_SSR_EXPRESS__;

  // app.listen(8888, async () => {
  //   const url = (route) => `http://localhost:8888${route}`;

  //   spinner.create(`Building '/'`);
  //   await got(url('/'));

  //   spinner.create(`Building '/' (test 2)`);
  //   await got(url('/'));

  //   spinner.create(`Building '/' (test 3)`);
  //   await got(url('/'));

  //   spinner.clear('Success!');
github sindresorhus / alfy / test / fetch.js View on Github external
test('cache', async t => {
	const alfy = createAlfy();

	t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world'});
	t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world'});

	await delay(5000);

	t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world!'});
});
github zengfenfei / ringcentral-ts / test / subscription-reliability.ts View on Github external
let receivedSms;
		let messageListener = evt => {
			receivedSms = evt.body;
			subscription.removeListener('message', messageListener);
			notify('The subscription is alive. Notification delay:' + (Date.now() - sentTime));
			rc.account().extension().messageStore(receivedSms.id).delete({});
			rc.account().extension().messageStore(sentSms.id).delete({});
		};
		subscription.onMessage(messageListener);
		let sentSms = await rc.account().extension().sms().post({
			from: { phoneNumber: config.user.username },
			to: [{ phoneNumber: config.user.username }],
			text: 'Test sms to trigger subscription.'
		});
		let sentTime = Date.now();
		await delay(notificationTimeout * 60 * 1000);
		if (!receivedSms) {
			let msg = 'The notification does not arrive in ' + notificationTimeout + ' minutes.';
			await notify(msg);
			await subscription.cancel();
			process.exit(1);
		}
	}

delay

Delay a promise a specified amount of time

MIT
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis

Popular delay functions