( request: Request, task: Task, thenable: Thenable<any>, )
| 978 | } |
| 979 | |
| 980 | function serializeThenable( |
| 981 | request: Request, |
| 982 | task: Task, |
| 983 | thenable: Thenable<any>, |
| 984 | ): number { |
| 985 | const newTask = createTask( |
| 986 | request, |
| 987 | (thenable: any), // will be replaced by the value before we retry. used for debug info. |
| 988 | task.keyPath, // the server component sequence continues through Promise-as-a-child. |
| 989 | task.implicitSlot, |
| 990 | task.formatContext, |
| 991 | request.abortableTasks, |
| 992 | enableProfilerTimer && |
| 993 | (enableComponentPerformanceTrack || enableAsyncDebugInfo) |
| 994 | ? task.time |
| 995 | : 0, |
| 996 | __DEV__ ? task.debugOwner : null, |
| 997 | __DEV__ ? task.debugStack : null, |
| 998 | __DEV__ ? task.debugTask : null, |
| 999 | ); |
| 1000 | |
| 1001 | switch (thenable.status) { |
| 1002 | case 'fulfilled': { |
| 1003 | forwardDebugInfoFromThenable(request, newTask, thenable, null, null); |
| 1004 | // We have the resolved value, we can go ahead and schedule it for serialization. |
| 1005 | newTask.model = thenable.value; |
| 1006 | pingTask(request, newTask); |
| 1007 | return newTask.id; |
| 1008 | } |
| 1009 | case 'rejected': { |
| 1010 | forwardDebugInfoFromThenable(request, newTask, thenable, null, null); |
| 1011 | const x = thenable.reason; |
| 1012 | erroredTask(request, newTask, x); |
| 1013 | return newTask.id; |
| 1014 | } |
| 1015 | default: { |
| 1016 | if (request.status === ABORTING) { |
| 1017 | // We can no longer accept any resolved values |
| 1018 | request.abortableTasks.delete(newTask); |
| 1019 | if (enableHalt && request.type === PRERENDER) { |
| 1020 | haltTask(newTask, request); |
| 1021 | finishHaltedTask(newTask, request); |
| 1022 | } else { |
| 1023 | const errorId: number = (request.fatalError: any); |
| 1024 | abortTask(newTask, request, errorId); |
| 1025 | finishAbortedTask(newTask, request, errorId); |
| 1026 | } |
| 1027 | return newTask.id; |
| 1028 | } |
| 1029 | if (typeof thenable.status === 'string') { |
| 1030 | // Only instrument the thenable if the status if not defined. If |
| 1031 | // it's defined, but an unknown value, assume it's been instrumented by |
| 1032 | // some custom userspace implementation. We treat it as "pending". |
| 1033 | break; |
| 1034 | } |
| 1035 | const pendingThenable: PendingThenable<mixed> = (thenable: any); |
| 1036 | pendingThenable.status = 'pending'; |
| 1037 | pendingThenable.then( |
no test coverage detected