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

shy-Do

v1.1.7

Published

npm install shy-Do ###支持UMD加载

Downloads

117

Readme

#install

npm install shy-Do

###支持UMD加载

#description

本质是任务队列,将一个个任务放入一个数组,按顺序执行,碰到wait类型的暂停执行,等待wait完成(ps:出现错误也被视为完成)后再从上次的位置继续执行,全部执行完成后清空任务队列

#API const Do = require('shy-Do') //静态属性 Do .version //版本号 //静态方法 .isDo(obj) //判定某个值是不是Do对象 .Symbol(obj) //返回一个对象 new .scope(doFunc,catchFunc) //安全地执行操作 new

let a = new Do()
a
//实例方法
.wait(function(rl,rj,val){})	//将一个延迟事件加入任务队列
.done(function(val){})			//将一个事件加入任务队列
.catch(function(err){})			//捕捉错误,和promise中的catch行为一致
.then(f1,f2)					//语法糖,返回一个新的Do对象
.result(f1,f2)					//f1|f2各自会得到Do对象的value|error,但他们不会改变Do对象的value|error
.state() 						//返回状态{state,value,error} new

//实例属性
.name							//'Do'
.constructor					//Do对象的构造函数,用来判断是不是Do对象

#重要版本更新

1.1.0 删除了.depend实例方法,查看属性移至实例方法.state 1.0.3 修复then,万物从new Do()开始 1.0.0 最终wait的参数顺序由(val,rl,rj)改为(rl,rj,val),选择和Promise保持一致,因为我在实战中发现.wait多写个reject也没什么的,倒是.result中写个null反而意味不明,顺带可以推广Promise何乐不为

0.2.1 修复depend

0.1.8 wait的参数顺序由(rl,rj,val)改为(val,rl,rj),不与Promise的参数顺序保持一致

0.1.4 result如果抛出一个错误,现在不会影响原来Do的结果

#已知问题 某些情况下会发生回调溢出,如下:

var x = Do.wait(function(rl,rj){
	setTimeout(function(){rl(7)},2000)
})
for(var i=0;i<10000;i++){
	x = x.then(fucntion(i){
		return i+1
	})
}
//x的值直到最后一个then执行都不会被释放,导致了溢出,这种情况改用done
x.then(funciton(i){
	console.log(7777)
})

这个时候我选择抛(go)出(die)异常