# delay

### 说明

&#x20;延迟`wait`毫秒后执行处理器`callback`

### 源码

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

### 用法

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

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

describe('delay', () => {
  test('delay should fire the callback after wait ms', () => {
    const received = function () {
      expect(true).toBeTruthy();
    }

    delay(received, 500);
  });

  test('delay should receive params that passed', () => {
    const received = function (name: string, age: number) {
      expect(name).toBe('ddzy');
      expect(age).toBe(21);
    }

    delay(received, 1000, 'ddzy', 21);
  });

  test('delay should return the timeout id', () => {
    const received = function () {
      expect(true).toBeTruthy();
    }

    const result = delay(received, 1500);

    expect(typeof result).toBe('number');
  });
});
```

{% 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/delay.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.
