@@ -8,41 +8,39 @@ import config from './config';
8
8
import cluster = require( 'cluster' ) ;
9
9
import app from './routes' ;
10
10
import parseArgv from './utils/parseArgv' ;
11
- const async = require ( 'async' ) ;
12
11
let args = parseArgv ( [ ] , [ 'DEBUG' ] ) ;
13
12
14
- async . series (
15
- [
16
- Storage . start . bind ( Storage ) ,
17
- Worker . start . bind ( Worker ) ,
18
- async ( cb : CallbackType ) => {
19
- let p2pServices = [ ] as Array < P2pService > ;
20
- for ( let chain of Object . keys ( config . chains ) ) {
21
- for ( let network of Object . keys ( config . chains [ chain ] ) ) {
22
- const chainConfig = config . chains [ chain ] [ network ] ;
23
- const hasChainSource = chainConfig . chainSource !== undefined ;
24
- if ( ! hasChainSource || chainConfig . chainSource === 'p2p' ) {
25
- let p2pServiceConfig = Object . assign (
26
- config . chains [ chain ] [ network ] ,
27
- { chain, network }
28
- ) ;
29
- p2pServices . push ( new P2pService ( p2pServiceConfig ) ) ;
30
- }
31
- }
13
+ const startServices = async ( ) => {
14
+ await Storage . start ( { } ) ;
15
+ await Worker . start ( ) ;
16
+
17
+ // TODO this needs to move to a static p2pService method
18
+ let p2pServices = [ ] as Array < P2pService > ;
19
+ for ( let chain of Object . keys ( config . chains ) ) {
20
+ for ( let network of Object . keys ( config . chains [ chain ] ) ) {
21
+ const chainConfig = config . chains [ chain ] [ network ] ;
22
+ const hasChainSource = chainConfig . chainSource !== undefined ;
23
+ if ( ! hasChainSource || chainConfig . chainSource === 'p2p' ) {
24
+ let p2pServiceConfig = Object . assign (
25
+ config . chains [ chain ] [ network ] ,
26
+ { chain, network }
27
+ ) ;
28
+ p2pServices . push ( new P2pService ( p2pServiceConfig ) ) ;
32
29
}
33
- await Promise . all ( p2pServices . map ( p2pService => p2pService . start ( ) ) ) . then (
34
- cb
35
- ) ;
36
- }
37
- ] ,
38
- function ( ) {
39
- const shouldRunDebug = cluster . isMaster && args . DEBUG ;
40
- const shouldRunCluster = cluster . isWorker && ! args . DEBUG ;
41
- if ( shouldRunDebug || shouldRunCluster ) {
42
- const server = app . listen ( config . port , function ( ) {
43
- logger . info ( `API server started on port ${ config . port } ` ) ;
44
- } ) ;
45
- server . timeout = 600000 ;
46
30
}
47
31
}
48
- ) ;
32
+ await Promise . all ( p2pServices . map ( p2pService => p2pService . start ( ) ) ) ;
33
+
34
+ // TODO this needs to move to an api service
35
+ const shouldRunDebug = cluster . isMaster && args . DEBUG ;
36
+ const shouldRunCluster = cluster . isWorker && ! args . DEBUG ;
37
+ if ( shouldRunDebug || shouldRunCluster ) {
38
+ const server = app . listen ( config . port , function ( ) {
39
+ logger . info ( `API server started on port ${ config . port } ` ) ;
40
+ } ) ;
41
+ // TODO this should be config driven
42
+ server . timeout = 600000 ;
43
+ }
44
+ } ;
45
+
46
+ startServices ( ) ;
0 commit comments