3.0.4 • Published 8 years ago

sas v3.0.4

Weekly downloads
71
License
MIT
Repository
github
Last release
8 years ago

English Sas 3.0.3Sas 3.0.4

Sas 3

Sas是javascript的一个简单的可递归的异步控制库,它使用Array代表串行,使用Object代表并行,使用Function代表任务。串行和并行可无限嵌套,它将会递归执行,无论多深,都能返回你想要的结果。它很小,源代码在包含很多注释和空格的情况下,仍不到200行。

安装npm install sas

Demo: 使用sas寻找磁盘最深处

var fs = require('fs');
var sas = require('sas');
var rootDir = '/', depth = 0, deepestPath;

function readdir(cb, i) {
  var indexs = i.indexs(), path = rootDir + indexs.join('/');
  if (indexs.length > depth) { //record
    depth = indexs.length;
    deepestPath = path;
  }
  fs.readdir(path, function(err, files) {
    if (err || !files.length) return cb();
    var tasks = {}, i = 0, len = files.length;
    for (; i < len; i++) {
      tasks[files[i]] = path + '/' + files[i];
    }
    cb('$reload', tasks);
  });
}

function stat(path) { //iterator
  return function(cb) {
    fs.lstat(path, function(err, stat) {
      if (err || stat.isSymbolicLink()) return cb();
      if (stat.isDirectory()) {
        return cb('$reload', readdir);
      }
      cb();
    });
  }
}

console.log('Exploring disk\'s deepest depth...');
console.time('time cost');

sas(readdir ,stat, function() {
  console.log('Deepest depth:',  depth);
  console.log('Deepest path:', deepestPath);
  console.timeEnd('time cost');
});

这个demo会异步的浏览你硬盘上所有文件/文件夹,找出最深的那个。最后结束,并把结果告诉你。 如果你想知道sas是怎么做到的,请访问: sas 2 文档

sas 3 中文文档

sas 3 English docs

前端直接src

在本项目根目录下./dist有打包好的文件供前端使用,支持amd加载。如果没有amd的话,会暴露到全局一个变量:sas

浏览器支持

不支持8及更早版本的IE浏览器。

3.0.4

8 years ago

3.0.3

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.13

9 years ago

2.0.12

10 years ago

2.0.11

10 years ago

2.0.9

10 years ago

2.0.8

10 years ago

2.0.7

10 years ago

2.0.6

10 years ago

2.0.3

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

0.1.20

10 years ago

0.1.19

10 years ago

0.1.18

10 years ago

0.1.17

10 years ago

0.1.15

10 years ago

0.1.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.1

10 years ago