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

asynq

v1.0.3

Published

control flow library for ES6 Generators

Downloads

11

Readme

asynqについて

asynqはES6 Generatorsを使用した非同期処理ライブラリです。 機能はほぼcoと同等となっていますが、 一部機能の違いがあり、また拡張が行われています。

#coとの違いについて

  • ジェネレータ関数に引数を渡すことができます
  • yieldに非同期タスクを要求する際、Object型は使用できません(Arrayは対応しています)
  • yieldにPromise、Array、Function、GeneratorFunction、Generator以外を渡した場合にエラーとはなりません
  • yieldに上記以外を渡す場合用のコールバックを作成する機能があります

#API

##asynq(fn*|fn)

ジェネレータを使用した非同期処理を実行し結果を受け取るPromiseを返します。 最初の引数にはジェネレータ及びジェネレータ関数を使用することができます。 それ以外の場合はその値(関数の場合はその評価結果)を返すPromiseを返します。

以降の引数にはジェネレータ関数及び任意の関数用の引数を渡すことができます。

###asynqの例

asynq(function*(){
  var result = Promise.resolve(123);  
  return result;
}).
then(function(data){
  //非同期処理の終了結果の受け取り
  console.log(data); //=> 123
}).
catch(function(err){
  //エラー処理
});

このコードを実行すると123が出力されます。

###asynqの例(エラー)

asynq(function*(){
  var result = Promise.reject(new Error("foo"));  
  return result;
}).
then(function(data){
  //非同期処理の終了結果の受け取り
  console.log(data);
}).
catch(function(err){
  //エラー処理
  console.log(err.message);//=>foo
});

このコードを実行するとエラーハンドラ(catch)でfooが出力されます。

###asynq.callbackを使用した例

asynq(function*(a, b, c){
  console.log("a");
  yield setTimeout(asynq.callback, a); //1秒待機
  console.log("b");
  yield setTimeout(asynq.callback, b); //2秒待機
  console.log("c");
  yield setTimeout(asynq.callback, c); //3秒待機
  console.log("done");
  
  return 123;
}, 1000, 2000, 3000).
then(function(data){
  //非同期処理の終了結果の受け取り
  console.log(data); //=> 123
}).
catch(function(err){
  //エラー処理
});

このコードを実行するとa,b,c,done,123と順に出力されます。

#!書き途中