| 819 | } |
| 820 | |
| 821 | void AsyncWritableStream::end() |
| 822 | { |
| 823 | switch (state) |
| 824 | { |
| 825 | case State::Stopped: |
| 826 | if (canEndWritable()) |
| 827 | { |
| 828 | state = State::Ended; |
| 829 | eventFinish.emit(); |
| 830 | if (autoDestroy) |
| 831 | { |
| 832 | destroy(); |
| 833 | } |
| 834 | } |
| 835 | else |
| 836 | { |
| 837 | state = State::Ending; |
| 838 | } |
| 839 | break; |
| 840 | case State::Writing: |
| 841 | // We need to wait for current in-flight write to end |
| 842 | state = State::Ending; |
| 843 | break; |
| 844 | case State::Destroying: { |
| 845 | // Invalid state, already destroyed or already destroying |
| 846 | eventError.emit(Result::Error("AsyncWritableStream::end - destroy already called")); |
| 847 | } |
| 848 | break; |
| 849 | case State::Ending: |
| 850 | case State::Ended: { |
| 851 | // Invalid state, already ended or already ending |
| 852 | eventError.emit(Result::Error("AsyncWritableStream::end - already called")); |
| 853 | } |
| 854 | break; |
| 855 | case State::Errored: break; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | void AsyncWritableStream::destroy() |
| 860 | { |