main
js 86 lines 3.42 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import type {
11 ReactDebugInfo,
12 ReactComponentInfo,
13 ReactStackTrace,
14 } from 'shared/ReactTypes';
15
16 export const IO_NODE = 0;
17 export const PROMISE_NODE = 1;
18 export const AWAIT_NODE = 2;
19 export const UNRESOLVED_PROMISE_NODE = 3;
20 export const UNRESOLVED_AWAIT_NODE = 4;
21
22 type PromiseWithDebugInfo = interface extends Promise<any> {
23 _debugInfo?: ReactDebugInfo,
24 };
25
26 export type IONode = {
27 tag: 0,
28 owner: null | ReactComponentInfo,
29 stack: null | ReactStackTrace, // callsite that spawned the I/O
30 start: number, // start time when the first part of the I/O sequence started
31 end: number, // we typically don't use this. only when there's no promise intermediate.
32 promise: null, // not used on I/O
33 awaited: null, // I/O is only blocked on external.
34 previous: null | AwaitNode | UnresolvedAwaitNode, // the preceeding await that spawned this new work
35 };
36
37 export type PromiseNode = {
38 tag: 1,
39 owner: null | ReactComponentInfo,
40 stack: null | ReactStackTrace, // callsite that created the Promise
41 start: number, // start time when the Promise was created
42 end: number, // end time when the Promise was resolved.
43 promise: WeakRef<PromiseWithDebugInfo>, // a reference to this Promise if still referenced
44 awaited: null | AsyncSequence, // the thing that ended up resolving this promise
45 previous: null | AsyncSequence, // represents what the last return of an async function depended on before returning
46 };
47
48 export type AwaitNode = {
49 tag: 2,
50 owner: null | ReactComponentInfo,
51 stack: null | ReactStackTrace, // callsite that awaited (using await, .then(), Promise.all(), ...)
52 start: number, // when we started blocking. This might be later than the I/O started.
53 end: number, // when we unblocked. This might be later than the I/O resolved if there's CPU time.
54 promise: WeakRef<PromiseWithDebugInfo>, // a reference to this Promise if still referenced
55 awaited: null | AsyncSequence, // the promise we were waiting on
56 previous: null | AsyncSequence, // the sequence that was blocking us from awaiting in the first place
57 };
58
59 export type UnresolvedPromiseNode = {
60 tag: 3,
61 owner: null | ReactComponentInfo,
62 stack: null | ReactStackTrace, // callsite that created the Promise
63 start: number, // start time when the Promise was created
64 end: -1.1, // set when we resolve.
65 promise: WeakRef<PromiseWithDebugInfo>, // a reference to this Promise if still referenced
66 awaited: null | AsyncSequence, // the thing that ended up resolving this promise
67 previous: null, // where we created the promise is not interesting since creating it doesn't mean waiting.
68 };
69
70 export type UnresolvedAwaitNode = {
71 tag: 4,
72 owner: null | ReactComponentInfo,
73 stack: null | ReactStackTrace, // callsite that awaited (using await, .then(), Promise.all(), ...)
74 start: number, // when we started blocking. This might be later than the I/O started.
75 end: -1.1, // set when we resolve.
76 promise: WeakRef<PromiseWithDebugInfo>, // a reference to this Promise if still referenced
77 awaited: null | AsyncSequence, // the promise we were waiting on
78 previous: null | AsyncSequence, // the sequence that was blocking us from awaiting in the first place
79 };
80
81 export type AsyncSequence =
82 | IONode
83 | PromiseNode
84 | AwaitNode
85 | UnresolvedPromiseNode
86 | UnresolvedAwaitNode;