File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 1
- /** Module Entrypoint */
1
+ import { Protocol , Dependency } from "./protocol/protocol" ;
2
+
3
+ class Gotham {
4
+ moduleId : string ;
5
+ protocol : Protocol
6
+ constructor ( ) {
7
+ this . protocol = new Protocol ( ) ;
8
+ }
9
+ async initialize ( moduleId : string , version : string , deps : Dependency ) {
10
+ return await this . protocol . sendRequest (
11
+ this . protocol . initialize ( moduleId , version , deps ) ,
12
+ ) ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { constants } from "../constants";
2
2
import { ConnectOpts } from 'net' ;
3
3
import { ConnectionOptions } from 'tls' ;
4
4
5
- interface Dependency {
5
+ export interface Dependency {
6
6
[ type : string ] : string ;
7
7
}
8
8
@@ -87,9 +87,17 @@ export class Protocol {
87
87
88
88
private connection : GothamConnection ;
89
89
90
- private async sendRequest ( obj : any , cb : Function ) {
90
+ async sendRequest ( obj : any ) {
91
91
await this . connection . send ( obj ) ;
92
- this . requests [ obj . requestId ] = cb ;
92
+ return new Promise ( ( resolve , reject ) => {
93
+ this . requests [ obj . requestId ] = ( res ) => {
94
+ if ( res ) {
95
+ resolve ( res ) ;
96
+ } else {
97
+ reject ( res ) ;
98
+ }
99
+ }
100
+ } ) ;
93
101
}
94
102
95
103
private generateRequestId ( ) {
You can’t perform that action at this time.
0 commit comments