# after

### 说明

&#x20;创建并返回一个函数, 等待函数运行指定`次数`后执行处理器

### 源码

<https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/function/after>

### 用法

{% code title="after.test.ts" %}

```typescript
import { after } from "../../utility/function/after";

describe('after', () => {
  test('after should fire the handler with no params after the special times of function call', () => {
    function doingWorkAsync(
      props: { type: string, sign: (...args: any[]) => void },
    ) {
      setTimeout(() => {
        props.sign();
      }, 0);
    }

    const employees = ['jack', 'rose', 'riven'];
    const fragment = after(employees.length, () => {
      expect(true).toBeTruthy();
    });

    for (const employee of employees) {
      doingWorkAsync({ type: employee, sign: fragment });
    }
  });

  test('after should fire the handler with any params after special times of function call', () => {
    function doingWorkAsyncWithParams(
      props: { type: string, sign: (...args: any[]) => void },
    ) {
      setTimeout(() => {
        props.sign(props.type);
      }, 0);
    }

    const employees = ['jack', 'rose', 'riven'];
    const fragment = after(employees.length, (type) => {
      expect(type).toBe('riven');
    });

    for (const employee of employees) {
      doingWorkAsyncWithParams({ type: employee, sign: fragment });
    }
  });
})
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ddzy.gitbook.io/ts-utility-plugins-docs/utility/utility-function/after.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
