(stream, state)
| 947 | } |
| 948 | |
| 949 | function finish(stream, state) { |
| 950 | state.pendingcb--; |
| 951 | state[kState] |= kFinished; |
| 952 | |
| 953 | callFinishedCallbacks(state, null); |
| 954 | |
| 955 | stream.emit('finish'); |
| 956 | |
| 957 | if ((state[kState] & kAutoDestroy) !== 0) { |
| 958 | // In case of duplex streams we need a way to detect |
| 959 | // if the readable side is ready for autoDestroy as well. |
| 960 | const rState = stream._readableState; |
| 961 | const autoDestroy = !rState || ( |
| 962 | rState.autoDestroy && |
| 963 | // We don't expect the readable to ever 'end' |
| 964 | // if readable is explicitly set to false. |
| 965 | (rState.endEmitted || rState.readable === false) |
| 966 | ); |
| 967 | if (autoDestroy) { |
| 968 | stream.destroy(); |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | function callFinishedCallbacks(state, err) { |
| 974 | if ((state[kState] & kOnFinished) === 0) { |
no test coverage detected
searching dependent graphs…