4.1.2 • Published 9 months ago

aocudeo v4.1.2

Weekly downloads
-
License
GPL-2.0-or-later
Repository
github
Last release
9 months ago

Aocudeo

github action github action Coverage Status

通过注册位置信息并在其上绑定工作器回调,本包可用于以正确的顺序组织异步或同步代码流程。

An Organizer of Code Units that Depend on Each Other - Aocudeo, can organize your pipelining work with the correct order through the 'Position' registered by 'Workers'.

用例 Usage

加载插件 Loading Plugins

  1. 在索引模块中弄个加载器用来加载模块。

    Get a public loader for your plugins in the index.

    import Loader from 'aocudeo/async';
    
    export const loader = new Loader({ reuseable: false });
  2. 根据插件名称和位置信息插入插件。

    Insert the plugin with its name and dependencies' name.

    loader
      .addPosition('foo', {
        after: ['bar', 'baz'],
        preOf: 'foobar',
      })
      .addWorker('foo', async () => {
        await import('./plugins/foo.ts');
      });
  3. loader.execute();

简单流程工作 Simple Pipeline Work

借以 p-graph 的示例代码为例。

Do what p-graph's sample code do.

import Organizer, { Positions } from 'aocudeo/async';

const workers = new Map([
  ["putOnShirt", { run: () => Promise.resolve("put on your shirt") }],
  ["putOnShorts", { run: () => Promise.resolve("put on your shorts") }],
  ["putOnJacket", { run: () => Promise.resolve("put on your jacket") }],
  ["putOnShoes", { run: () => Promise.resolve("put on your shoes") }],
  ["tieShoes", { run: () => Promise.resolve("tie your shoes") }],
]);

const positions: Positions = [
  // You need to put your shoes on before you tie them!
  ["putOnShoes", "tieShoes"],
  ["putOnShirt", "putOnJacket"],
  ["putOnShorts", "putOnJacket"],
  ["putOnShorts", "putOnShoes"],
];

await new Organizer({ workers, positions }).execute();

流水线处理 Pipeline Process

以下这个用例导出一个用于得到一个穿好衣服的人的函数 getPerson

The following usage exports getPerson to obtain a person dressed properly.

import Organizer from "aocudeo/async";

export interface Person {
  shorts?: 'shorts';
  shoes?: 'shoes';
  tied: boolean;
}

const organizer = new Organizer<Person>()
  .addPositions({
    putOnShoes: 'putOnShorts',
    tieShoes: { postOf: 'putOnShoes' },
  })
  .addWorkers({
    async putOnShorts({ data: person }) {
      person.shorts = await Promise.resolve('shorts');
    },
    async putOnShoes({ data: person }) {
      person.shoes = await Promise.resolve('shoes');
    },
    async tieShoes({ data: person }) {
      person.tied = await Promise.resolve(true);
    },
  });

export async function getPerson() {
  return await organizer.execute({ tied: false });
}

链接 Links

  • p-graph

    功能上与本包类似。

    Functionally similar to this package.

4.0.1

10 months ago

4.0.0

10 months ago

4.1.2

9 months ago

4.1.1

9 months ago

3.4.3

11 months ago

3.4.0

11 months ago

3.4.2

11 months ago

3.4.1

11 months ago

3.1.2

11 months ago

3.0.2

11 months ago

3.1.0

11 months ago

3.1.4

11 months ago

2.8.0

12 months ago

2.7.4

12 months ago

2.7.3

12 months ago

2.7.2

12 months ago

2.4.0

12 months ago

2.3.1

12 months ago

2.1.2

1 year ago

2.1.1

1 year ago