File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as _ from "lodash" ;
2
+
3
+ import { UnifiedSteemTransaction } from "../blockchain/UnifiedSteemTransaction" ;
4
+ import { AsyncIterator } from "../iterator/AsyncIterator" ;
5
+
6
+ export class BatchToTrxIterator implements AsyncIterator < UnifiedSteemTransaction > {
7
+ private batchIterator : AsyncIterator < UnifiedSteemTransaction [ ] > ;
8
+ private currentBatch : UnifiedSteemTransaction [ ] = [ ] ;
9
+ private done : boolean = false ;
10
+
11
+ public constructor ( batchIterator : AsyncIterator < UnifiedSteemTransaction [ ] > ) {
12
+ this . batchIterator = batchIterator ;
13
+ }
14
+
15
+ public async next ( ) : Promise < IteratorResult < UnifiedSteemTransaction > > {
16
+ if ( this . done ) throw AsyncIterator . AsyncIteratorError . iteratorAlreadyDoneError ( ) ;
17
+ await this . loadNextBatchIfRequired ( ) ;
18
+
19
+ const shifted = this . currentBatch . shift ( ) ;
20
+ if ( ! shifted ) throw new Error ( "BatchToTrxIterator: current batch could not be shifted" ) ;
21
+
22
+ return { done : this . done , value : shifted } ;
23
+ }
24
+
25
+ private async loadNextBatchIfRequired ( ) {
26
+ if ( this . currentBatch . length === 0 ) {
27
+ const { done, value } = await this . batchIterator . next ( ) ;
28
+ this . currentBatch = value ;
29
+ this . done = done ;
30
+ }
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments