@aboutweb/promise-routine 中文文档教程

发布于 6年前 浏览 25 项目主页 更新于 3年前

promise-routine

一个承诺的基础例程,它建立了可以以同步方式执行的中继线。

Usage:

import * as routine from "@aboutweb/promise-routine";

let trunk = routine([
  /*
    if you don't return a Promise
    and the function itself is not async
    next will get called internally with the same args
  */
  function(ctx) {
    ctx.setup = () => {
      //...
    }
  }
  function(ctx, next) {
    //init...

    return next(ctx).then(() => {
      //bubble up
      ctx.setup();
    });
  },
  async function(ctx, next) {
    ctx.value = true

    await sleep(100);
    await next(ctx);

  }
])

let ctx = {};

trunk(ctx).then((ctx) => {
  //all finised
});

promise-routine

A promised base routine that builds up trunks which can be executed in a syncrounized fashion.

Usage:

import * as routine from "@aboutweb/promise-routine";

let trunk = routine([
  /*
    if you don't return a Promise
    and the function itself is not async
    next will get called internally with the same args
  */
  function(ctx) {
    ctx.setup = () => {
      //...
    }
  }
  function(ctx, next) {
    //init...

    return next(ctx).then(() => {
      //bubble up
      ctx.setup();
    });
  },
  async function(ctx, next) {
    ctx.value = true

    await sleep(100);
    await next(ctx);

  }
])

let ctx = {};

trunk(ctx).then((ctx) => {
  //all finised
});
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文