@@ -60,51 +60,6 @@ impl Dispatcher {
60
60
self . new_root . set ( Some ( callback) ) ;
61
61
}
62
62
63
- fn create_root_context ( & self , context_id : u32 ) {
64
- let new_context = match self . new_root . get ( ) {
65
- Some ( f) => f ( context_id) ,
66
- None => Box :: new ( NoopRoot ) ,
67
- } ;
68
- if self
69
- . roots
70
- . borrow_mut ( )
71
- . insert ( context_id, new_context)
72
- . is_some ( )
73
- {
74
- panic ! ( "duplicate context_id" )
75
- }
76
- }
77
-
78
- fn create_stream_context ( & self , context_id : u32 , root_context_id : u32 ) {
79
- let new_context = match self . roots . borrow ( ) . get ( & root_context_id) {
80
- Some ( root_context) => root_context. create_stream_context ( context_id, root_context_id) ,
81
- None => panic ! ( "invalid root_context_id" ) ,
82
- } ;
83
- if self
84
- . streams
85
- . borrow_mut ( )
86
- . insert ( context_id, new_context)
87
- . is_some ( )
88
- {
89
- panic ! ( "duplicate context_id" )
90
- }
91
- }
92
-
93
- fn create_http_context ( & self , context_id : u32 , root_context_id : u32 ) {
94
- let new_context = match self . roots . borrow ( ) . get ( & root_context_id) {
95
- Some ( root_context) => root_context. create_http_context ( context_id, root_context_id) ,
96
- None => panic ! ( "invalid root_context_id" ) ,
97
- } ;
98
- if self
99
- . http_streams
100
- . borrow_mut ( )
101
- . insert ( context_id, new_context)
102
- . is_some ( )
103
- {
104
- panic ! ( "duplicate context_id" )
105
- }
106
- }
107
-
108
63
fn register_callout ( & self , token_id : u32 ) {
109
64
if self
110
65
. callouts
@@ -118,17 +73,46 @@ impl Dispatcher {
118
73
119
74
fn on_create_context ( & self , context_id : u32 , root_context_id : u32 ) {
120
75
if root_context_id == 0 {
121
- self . create_root_context ( context_id) ;
76
+ let root_context = match self . new_root . get ( ) {
77
+ Some ( f) => f ( context_id) ,
78
+ None => Box :: new ( NoopRoot ) ,
79
+ } ;
80
+ if self
81
+ . roots
82
+ . borrow_mut ( )
83
+ . insert ( context_id, root_context)
84
+ . is_some ( )
85
+ {
86
+ panic ! ( "duplicate context_id" )
87
+ }
122
88
} else if let Some ( root_context) = self . roots . borrow ( ) . get ( & root_context_id) {
123
89
match root_context. get_type ( ) {
124
- ContextType :: HttpContext => self . create_http_context ( context_id, root_context_id) ,
90
+ ContextType :: HttpContext => {
91
+ let http_context = root_context. create_http_context ( context_id) ;
92
+ if self
93
+ . http_streams
94
+ . borrow_mut ( )
95
+ . insert ( context_id, http_context)
96
+ . is_some ( )
97
+ {
98
+ panic ! ( "duplicate context_id" )
99
+ }
100
+ }
125
101
ContextType :: StreamContext => {
126
- self . create_stream_context ( context_id, root_context_id)
102
+ let stream_context = root_context. create_stream_context ( context_id) ;
103
+ if self
104
+ . streams
105
+ . borrow_mut ( )
106
+ . insert ( context_id, stream_context)
107
+ . is_some ( )
108
+ {
109
+ panic ! ( "duplicate context_id" )
110
+ }
127
111
}
128
- ContextType :: RootContext => panic ! ( "missing constructors " ) ,
112
+ ContextType :: RootContext => panic ! ( "missing ContextType on root_context " ) ,
129
113
}
130
114
} else {
131
- panic ! ( "missing constructors" )
115
+ panic ! ( "invalid root_context_id" ) ;
132
116
}
133
117
}
134
118
0 commit comments