Download next.js/packages/next/src/server/after/run-with-after.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/after/run-with-after.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/server/after/run-with-after.ts
-
curl -L -o run-with-after.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/after/run-with-after.ts
1.13 kB
| import { DetachedPromise } from '../../lib/detached-promise' | |
| import { CloseController } from '../web/web-on-close' | |
| import type { AfterContextOpts } from './after-context' | |
| import { AwaiterOnce } from './awaiter' | |
| type Ctx = { | |
| waitUntil: NonNullable<AfterContextOpts['waitUntil']> | |
| onClose: NonNullable<AfterContextOpts['onClose']> | |
| onTaskError: NonNullable<AfterContextOpts['onTaskError']> | |
| } | |
| export class AfterRunner { | |
| private awaiter = new AwaiterOnce() | |
| private closeController = new CloseController() | |
| private finishedWithoutErrors = new DetachedPromise<void>() | |
| readonly context: Ctx = { | |
| waitUntil: this.awaiter.waitUntil.bind(this.awaiter), | |
| onClose: this.closeController.onClose.bind(this.closeController), | |
| onTaskError: (error) => this.finishedWithoutErrors.reject(error), | |
| } | |
| public async executeAfter() { | |
| this.closeController.dispatchClose() | |
| await this.awaiter.awaiting() | |
| // if we got an error while running the callbacks, | |
| // thenthis is a noop, because the promise is already rejected | |
| this.finishedWithoutErrors.resolve() | |
| return this.finishedWithoutErrors.promise | |
| } | |
| } | |