Skip to content

Commit 18df6ab

Browse files
committed
document cancelAfter + mark cancelAfter as unstable
1 parent 7e56da4 commit 18df6ab

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

apps/website/docs/guide/02-commands/06-after-function.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,27 @@ The `after()` function will always be called, regardless of whether
4545
the command execution was successful or not.
4646

4747
:::
48+
49+
## Cancelling the after function
50+
51+
You can cancel the after function by calling the `cancelAfter`
52+
function with the ID of the after function.
53+
54+
```ts title="src/app/commands/ping.ts"
55+
import {
56+
unstable_after as after,
57+
unstable_cancelAfter as cancelAfter,
58+
} from 'commandkit';
59+
60+
export const chatInput: ChatInputCommand = async (ctx) => {
61+
const id = after(() => {
62+
console.log(
63+
'This will run after the command has finished executing.',
64+
);
65+
});
66+
67+
if (something) {
68+
cancelAfter(id);
69+
}
70+
};
71+
```

packages/commandkit/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export {
1010
type CommandKitEnvironmentInternalData,
1111
CommandKitEnvironment,
1212
CommandKitEnvironmentType,
13-
cancelAfter,
13+
cancelAfter as unstable_cancelAfter,
1414
after as unstable_after,
1515
} from './context/environment';
1616
export * from './app/index';

0 commit comments

Comments
 (0)