|
| 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 | +export const IO_NODE = 0; |
| 11 | +export const PROMISE_NODE = 1; |
| 12 | +export const AWAIT_NODE = 2; |
| 13 | + |
| 14 | +export type IONode = { |
| 15 | + tag: 0, |
| 16 | + stack: Error, // callsite that spawned the I/O |
| 17 | + start: number, // start time when the first part of the I/O sequence started |
| 18 | + end: number, // we typically don't use this. only when there's no promise intermediate. |
| 19 | + awaited: null, // I/O is only blocked on external. |
| 20 | + previous: null | AwaitNode, // the preceeding await that spawned this new work |
| 21 | +}; |
| 22 | + |
| 23 | +export type PromiseNode = { |
| 24 | + tag: 1, |
| 25 | + stack: Error, // callsite that created the Promise |
| 26 | + start: number, // start time when the Promise was created |
| 27 | + end: number, // end time when the Promise was resolved. |
| 28 | + awaited: null | AsyncSequence, // the thing that ended up resolving this promise |
| 29 | + previous: null, // where we created the promise is not interesting since creating it doesn't mean waiting. |
| 30 | +}; |
| 31 | + |
| 32 | +export type AwaitNode = { |
| 33 | + tag: 2, |
| 34 | + stack: Error, // callsite that awaited (using await, .then(), Promise.all(), ...) |
| 35 | + start: -1.1, // not used. We use the timing of the awaited promise. |
| 36 | + end: -1.1, // not used. |
| 37 | + awaited: null | AsyncSequence, // the promise we were waiting on |
| 38 | + previous: null | AsyncSequence, // the sequence that was blocking us from awaiting in the first place |
| 39 | +}; |
| 40 | + |
| 41 | +export type AsyncSequence = IONode | PromiseNode | AwaitNode; |
0 commit comments