npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flag-waiter

v1.0.5

Published

waiter for npm

Downloads

8

Readme

專案名稱

Waiter 的使用方式

簡介

語言 : Typescript/Javascript

主旨 :

  • WaitMilliseconds
  • Wait
  • WaitForAny
  • WaitForAll

快速開始

環境建立

npm

npm i flag-waiter

or yarn

yarn add flag-waiter

使用範例

引入 Package

  1. 建立 async function
  2. 加入下方程式碼

NodeJs

const waiter = require("flag-waiter");

ES

import * as waiter from "flag-waiter";
  1. 修改 start 的函式為 async

WaitMilliseconds

async function start() {
    console.log("開始");
    await waiter.WaitMilliseconds(3000); //等待3秒
    console.log("經過3秒");
}

Wait

建立一個可觸發的 Flag, 用以通知 waiter 停止等待

var flag;

async function start() {
    flag = new waiter.Flag("myFlag");
    console.log("開始");
    await waiter.Wait(flag, 10000); //flag , timeout(ms)
    console.log("flag被觸發或timeout");
}

//使用方式可做成button進行觸發
async function trigger() {
    await waiter.WaitMilliseconds(3000); //等待3秒
    flag.set(true); //觸發Flag
    console.log("觸發Flag");
}

start();
trigger();

WaitAll

建立多個 Flag, 需等待全部 Flag 被觸發或是全部 Timeout 才可繼續進行

var flag1;
var flag2;
async function start() {
    flag1 = new waiter.Flag("flag1");
    flag2 = new waiter.Flag("flag2");
    console.log("開始");
    await waiter.WaitAll([flag1, flag2], [10000, 10000]); //flag , timeout(ms)
    console.log("flag全被觸發或timeout");
}

//使用方式可做成button進行觸發
async function trigger1() {
    await waiter.WaitMilliseconds(3000); //等待3秒
    flag1.set(true); //觸發Flag
    console.log("觸發Flag1");
}

async function trigger2() {
    await waiter.WaitMilliseconds(5000); //等待3秒
    flag2.set(true); //觸發Flag
    console.log("觸發Flag2");
}

start();
trigger1();
trigger2();

WaitAny

建立多個 Flag, 任何一個 Flag 被觸發都會繼續進行

var flag1;
var flag2;
async function start() {
    flag1 = new waiter.Flag("flag1");
    flag2 = new waiter.Flag("flag2");
    console.log("開始");
    await waiter.WaitAny([flag1, flag2], [10000, 10000]); //flags , timeouts(ms)
    console.log("flag其中一個被觸發或timeout");
}

//使用方式可做成button進行觸發
async function trigger1() {
    await waiter.WaitMilliseconds(3000); //等待3秒
    flag1.set(true); //觸發Flag
    console.log("觸發Flag1");
}

async function trigger2() {
    await waiter.WaitMilliseconds(5000); //等待3秒
    flag2.set(true); //觸發Flag
    console.log("觸發Flag2");
}

start();
trigger1();
trigger2();