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 🙏

© 2025 – Pkg Stats / Ryan Hefner

centralperk

v0.4.0

Published

Manage Complex Work Flow

Downloads

1

Readme

centralperk

Manage Complex Work Flow

Code Async JS

Elegantly :)


author Meng G. [email protected]

date 2016-03-21

github https://github.com/gaomeng1900/centralperk


A flow controller based on Subscribe/Publish model and stream model

RequestsJS is required (already in this git , bower install requestsjs to get the updated)

Import in ADM/global way, both supported

centralperk.js contains the flow controler part. browser/node

centralperk.ext.js contains useful http part (get/post/put/delete) packed from requests.js. browser only

对于异步编程,有很多现成的解决方案包括

  • ES6 async/Promise
  • step.js
  • co.js
  • then.js
  • wind.js
  • so on...

但是接口还可以更简洁友好,尤其是处理包含异步编程的复杂任务流程时,step之间应该进一步解耦。

centralperk采用了类似于 publish-subscribe pattern 的方式处理异步回调顺序(事实上,前三个版本都是典型的publish-subscribe pattern),将同步任务和异步任务统一由事件中心管理。支持pipe风格的接口,以及针对十分复杂的逻辑的特殊接口:直接以瀑布流式的字面量定义流程。

实现一个订阅中心进行a->b, a->b&c的管理是容易的(centralperk第一版),但是涉及到多级流程时就要正确处理每次任务触发时所在的flow,并避免多条支线交叉时的引用冲突(第二版),另外还有对性能的优化和对ES6规范的支持(第三版)。

centralperk(v4)的核心在于任务链管理,使用闭包传递一个 stream 变量来标示当前调用/构造所在的flow 以及flow中的位置,来做到flow之间的完全隔离,同时并入重构后的requests.js, 获得更简洁更强大的restful调用接口,并增加了一些新的特性。

实例在test.coffee中。

You may find examples in test.coffee

PS. this manual is long and boring


a example

栗子

Suppose that there a 7 jobs(sync ones and async ones), and you want them excecute in flow like this

What will you do... (゚д゚)

Before you crash your ⌨

0. sign the functions

# coffeescript

PERK.sign 'task0', (args, done)->
    # do something
    done(args)


PERK.sign 'task1', (args, done)->
	# maybe some XHR
	PERK.get {url:'http://httpbin.org/ip'}, args, done


PERK.sign 'task2', (args, done)->
	# maybe your own async task
	some_async_fun(args, done)
    
# other 4 ones...

前方高~~萌~~能

1. set the stream-like flow

# coffeescript

PERK.stream {
    'task0':
        'task1':
            'task2':
                'task3':{}
        'task4':
            'task5':{}
            'task6':{}
}

2. Here we go!

PERK.task('task0', args)

You can set the flow in gulp.task.pipe way

# coffeescript

PERK.link 'task0' 
    .to 'task1', ['task6', 'task5']
    .to 'task2'
    .to 'task3'

# 0 → 1 → 2 → 3
#     ↓ ↘ 
#     ↘  5 
#       6
  
PERK.stream( { 'task0':{ 'task1':{ 'task2':{} } } } );
// equal to
PERK.link('task0').to('task1').to('task2');
// 0 → 1 → 2

API

sign

  • @param taskID {String} : name your task
  • @param fun {Function}: the task function
  • @return PERK {Object}
  • The first one is args(or what ever U call it).

  • Read more about Currying [https://en.wikipedia.org/wiki/Currying].

  • It will be passed from the previous fun in the flow or from PERK.task('taskName', args);

  • Call this function means the end of current function.

  • You can pass this done to any other function and call it anywhere you want.

sream

  • @param flow {Object/Map}
# coffeescript

PERK.stream {
    'task0':
        'task1':
            'task2':
                'task3':{}
        'task4':
            'task5':{}
            'task6':{}
    'task4':
    	'task7':{}
}
# 0 → 1 → 2 → 3
#   ↘ 
#     4 → 5 → 7
#      ↘ 
#        6
#
# 4 → 7

** important tip **

task

  • @param taskName {String}

  • @param args {Object}

  • Do some task. it will start a flow when this task is at the root of it.

link

  • @param taskName {String}

to

  • @param taskName {String}

get/post/put/delete

  • pack of XHR, based on Requests.js
  • see examples and doc of Requests.js [https://github.com/gaomeng1900/requests]