@@ -54,35 +54,38 @@ private function writeHead()
5454 $ stateRef = &$ this ->state ;
5555 $ pendingWrites = &$ this ->pendingWrites ;
5656
57- $ this
58- ->connect ()
59- ->done (
60- function (ConnectionInterface $ stream ) use ($ requestData , &$ streamRef , &$ stateRef , &$ pendingWrites ) {
61- $ streamRef = $ stream ;
57+ $ promise = $ this ->connect ();
58+ $ promise ->done (
59+ function (ConnectionInterface $ stream ) use ($ requestData , &$ streamRef , &$ stateRef , &$ pendingWrites ) {
60+ $ streamRef = $ stream ;
6261
63- $ stream ->on ('drain ' , array ($ this , 'handleDrain ' ));
64- $ stream ->on ('data ' , array ($ this , 'handleData ' ));
65- $ stream ->on ('end ' , array ($ this , 'handleEnd ' ));
66- $ stream ->on ('error ' , array ($ this , 'handleError ' ));
67- $ stream ->on ('close ' , array ($ this , 'handleClose ' ));
62+ $ stream ->on ('drain ' , array ($ this , 'handleDrain ' ));
63+ $ stream ->on ('data ' , array ($ this , 'handleData ' ));
64+ $ stream ->on ('end ' , array ($ this , 'handleEnd ' ));
65+ $ stream ->on ('error ' , array ($ this , 'handleError ' ));
66+ $ stream ->on ('close ' , array ($ this , 'handleClose ' ));
6867
69- $ headers = (string ) $ requestData ;
68+ $ headers = (string ) $ requestData ;
7069
71- $ more = $ stream ->write ($ headers . $ pendingWrites );
70+ $ more = $ stream ->write ($ headers . $ pendingWrites );
7271
73- $ stateRef = Request::STATE_HEAD_WRITTEN ;
72+ $ stateRef = Request::STATE_HEAD_WRITTEN ;
7473
75- // clear pending writes if non-empty
76- if ($ pendingWrites !== '' ) {
77- $ pendingWrites = '' ;
74+ // clear pending writes if non-empty
75+ if ($ pendingWrites !== '' ) {
76+ $ pendingWrites = '' ;
7877
79- if ($ more ) {
80- $ this ->emit ('drain ' );
81- }
78+ if ($ more ) {
79+ $ this ->emit ('drain ' );
8280 }
83- },
84- array ($ this , 'handleError ' )
85- );
81+ }
82+ },
83+ array ($ this , 'handleError ' )
84+ );
85+
86+ $ this ->on ('close ' , function () use ($ promise ) {
87+ $ promise ->cancel ();
88+ });
8689 }
8790
8891 public function write ($ data )
0 commit comments