@@ -44,12 +44,14 @@ enum IndexerCommand {
44
44
DropBlocks ( Vec < u64 > ) ,
45
45
RewriteBlocks ( Vec < u64 > ) ,
46
46
ReplayBlocks ( Vec < u64 > ) ,
47
- Stop ,
47
+ Terminate ,
48
48
}
49
49
50
+ #[ allow( dead_code) ]
50
51
enum CustomIndexerCommand {
51
52
UpdateApplyCallback ( Root < JsFunction > ) ,
52
53
UpdateUndoCallback ( Root < JsFunction > ) ,
54
+ Terminate ,
53
55
}
54
56
55
57
impl Finalize for OrdinalsIndexer { }
@@ -136,6 +138,9 @@ impl OrdinalsIndexer {
136
138
Ok ( CustomIndexerCommand :: UpdateUndoCallback ( callback) ) => {
137
139
undo_callback = Some ( callback) ;
138
140
}
141
+ Ok ( CustomIndexerCommand :: Terminate ) => {
142
+ return Ok ( ( ) )
143
+ }
139
144
_ => { }
140
145
}
141
146
}
@@ -179,8 +184,8 @@ impl OrdinalsIndexer {
179
184
IndexerCommand :: SyncBlocks => {
180
185
println ! ( "Will sync blocks" ) ;
181
186
}
182
- IndexerCommand :: Stop => {
183
- break ;
187
+ IndexerCommand :: Terminate => {
188
+ std :: process :: exit ( 0 ) ;
184
189
}
185
190
}
186
191
}
@@ -198,6 +203,11 @@ impl OrdinalsIndexer {
198
203
Ok ( true )
199
204
}
200
205
206
+ fn terminate ( & self ) -> Result < bool , String > {
207
+ let _ = self . command_tx . send ( IndexerCommand :: Terminate ) ;
208
+ Ok ( true )
209
+ }
210
+
201
211
fn replay_blocks ( & self , blocks : Vec < u64 > ) -> Result < bool , String > {
202
212
let _ = self . command_tx . send ( IndexerCommand :: ReplayBlocks ( blocks) ) ;
203
213
Ok ( true )
@@ -372,8 +382,13 @@ impl OrdinalsIndexer {
372
382
Ok ( cx. undefined ( ) )
373
383
}
374
384
375
- fn js_terminate ( mut _cx : FunctionContext ) -> JsResult < JsBoolean > {
376
- unimplemented ! ( ) ;
385
+ fn js_terminate ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
386
+ cx. this ( )
387
+ . downcast_or_throw :: < JsBox < OrdinalsIndexer > , _ > ( & mut cx) ?
388
+ . terminate ( )
389
+ . or_else ( |err| cx. throw_error ( err. to_string ( ) ) ) ?;
390
+
391
+ Ok ( cx. undefined ( ) )
377
392
}
378
393
379
394
fn js_on_block_apply ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
0 commit comments