Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(asyncNoop): add asyncNoop #903

Merged
merged 5 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/ja/reference/function/asyncNoop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# asyncNoop

非同期で何もしない関数です。 関数を要求する場所に空白を埋めるために使用したり、デフォルトで使用することができます。

## インターフェース

```typescript
function asyncNoop(): Promise<void>;
```

### 戻り値

(`Promise<void>`): `undefined` に解決する `Promise`。

## 例

```typescript
import { asyncNoop } from 'es-toolkit/function';

interface Props {
fetchData?: () => Promise<void>;
}

function MyComponent({ fetchData = asyncNoop }: Props) {
const handleFetchData = async () => {
// ここでfetchDataは関数であることが保証されているため、安全に呼び出すことができます。
await fetchData();
};

handleFetchData();
}
```
32 changes: 32 additions & 0 deletions docs/ko/reference/function/asyncNoop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# asyncNoop

비동기적으로 아무것도 하지 않는 함수예요. 함수를 요구하는 곳에 빈 자리를 채우기 위해 사용하거나, 기본값으로 사용할 수 있어요.

## 인터페이스

```typescript
function asyncNoop(): Promise<void>;
```

### 반환 값

(`Promise<void>`): `undefined`로 이행하는 `Promise`.

## 예시

```typescript
import { asyncNoop } from 'es-toolkit/function';

interface Props {
fetchData?: () => Promise<void>;
}

function MyComponent({ fetchData = asyncNoop }: Props) {
const handleFetchData = async () => {
// 여기서 fetchData는 undefined일 수 없어서, 자유롭게 부를 수 있어요.
await fetchData();
};

handleFetchData();
}
```
32 changes: 32 additions & 0 deletions docs/reference/function/asyncNoop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# asyncNoop

An asynchronous no-operation function that does nothing. This can be used as a placeholder or default function.

## Signature

```typescript
function asyncNoop(): Promise<void>;
```

### Returns

(`Promise<void>`): A Promise that resolves to undefined.

## Examples

```typescript
import { asyncNoop } from 'es-toolkit/function';

interface Props {
fetchData?: () => Promise<void>;
}

function MyComponent({ fetchData = asyncNoop }: Props) {
const handleFetchData = async () => {
// Here fetchData is guaranteed to be a function, so it's safe to call.
await fetchData();
};

handleFetchData();
}
```
32 changes: 32 additions & 0 deletions docs/zh_hans/reference/function/asyncNoop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# asyncNoop

一个非同步的空函数。 可以用来在函数需要的地方填充空白,或者作为默认值使用。

## 接口

```typescript
function asyncNoop(): Promise<void>;
```

### 返回值

(`Promise<void>`): 这个函数返回一个Promise,它将解析为undefined。
raon0211 marked this conversation as resolved.
Show resolved Hide resolved

## 示例

```typescript
import { asyncNoop } from 'es-toolkit/function';

interface Props {
fetchData?: () => Promise<void>;
}

function MyComponent({ fetchData = asyncNoop }: Props) {
const handleFetchData = async () => {
// 这里fetchData是函数,所以可以安全地调用。
await fetchData();
};

handleFetchData();
}
```
16 changes: 16 additions & 0 deletions src/function/asyncNoop.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';
import { asyncNoop } from './asyncNoop';

describe('asyncNoop', () => {
it('should be a function', () => {
expect(typeof asyncNoop).toBe('function');
});

it('should return a Promise', () => {
expect(asyncNoop()).toBeInstanceOf(Promise);
});

it('should resolve to undefined', async () => {
await expect(asyncNoop()).resolves.toBeUndefined();
});
});
10 changes: 10 additions & 0 deletions src/function/asyncNoop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* An asynchronous no-operation function that does nothing.
* This can be used as a placeholder or default function.
*
* @example
* asyncNoop(); // Does nothing
*
* @returns {Promise<void>} This function returns a Promise that resolves to undefined.
*/
export async function asyncNoop(): Promise<void> {}
1 change: 1 addition & 0 deletions src/function/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { after } from './after.ts';
export { ary } from './ary.ts';
export { asyncNoop } from './asyncNoop.ts';
export { before } from './before.ts';
export { curry } from './curry.ts';
export { curryRight } from './curryRight.ts';
Expand Down
Loading