1+ import _ from 'lodash'
2+
13import IPOS from '../main'
4+
25import subProcessIPCLoopback from './subProcessIPCLoopback'
3- import { withoutProcessSend } from './withoutProcessSendSync'
6+ import { withoutProcessSend , withoutProcessSendSync } from './withoutProcessSendSync'
47
58async function initWith ( setValue : ( main_ipos : IPOS ) => void , probeValue : ( sub_ipos : IPOS ) => void ) {
69 const sub_process = new subProcessIPCLoopback ( )
7- let main_ipos : IPOS
8- await withoutProcessSend ( async ( ) => {
10+ let main_ipos : IPOS , sub_ipos : IPOS
11+ await withoutProcessSendSync ( ( ) => {
912 main_ipos = IPOS . new ( ) as IPOS
1013 setValue ( main_ipos )
1114 } )
12- console . log ( 'sub_ipos' )
13- let sub_ipos = IPOS . new ( )
14- console . log ( 'withoutProcessSend' )
15- await withoutProcessSend ( async ( ) => {
16- console . log ( 'main_ipos.addProcess' )
15+
16+ await Promise . all ( [
1717 // @ts -ignore Argument of type 'subProcessIPCLoopback' is not assignable to parameter of type 'ChildProcess'
18- await main_ipos . addProcess ( sub_process )
19- console . log ( 'done main_ipos.addProcess' )
20- } )
21- console . log ( 'await sub_ipos' )
22- sub_ipos = await sub_ipos
18+ main_ipos . addProcess ( sub_process ) ,
19+ ( async ( ) => sub_ipos = await IPOS . new ( ) ) ( )
20+ ] )
21+
22+ // @ts -ignore Variable ' sub_ipos' is used before being assigned.
2323 probeValue ( sub_ipos )
24+
2425 sub_process . destroy ( )
2526}
2627
27- /* describe('Synchronising fields between processes', () => {
28+ describe ( 'Synchronisation of fields between processes (transferring existing fields) ' , ( ) => {
2829 const examples : { [ key : string ] : unknown } = {
2930 'string' : 'myString' ,
3031 'number' : 42 ,
@@ -33,7 +34,19 @@ async function initWith(setValue: (main_ipos: IPOS) => void, probeValue: (sub_ip
3334 mySecondValue : 42
3435 } ,
3536 'array' : [ 'myItem' , 42 ] ,
37+ 'map' : new Map ( Object . entries ( {
38+ myKey : 'myValue' ,
39+ mySecondValue : 42
40+ } ) ) ,
3641 'set' : new Set ( [ 'myItem' , 42 ] ) ,
42+ 'function' : ( a : number , b : number ) => a + b ,
43+ }
44+
45+ function customizer ( a : any , b : any ) {
46+ // compare function contents
47+ if ( [ typeof a , typeof b ] . every ( a => a === 'function' ) ) {
48+ return a . toString ( ) === b . toString ( ) ;
49+ }
3750 }
3851
3952 for ( const exampleKey in examples ) {
@@ -45,12 +58,11 @@ async function initWith(setValue: (main_ipos: IPOS) => void, probeValue: (sub_ip
4558 main_ipos . create ( 'myField' , value )
4659 } ,
4760 ( sub_ipos ) => {
48- console.log(value)
49- console.log(sub_ipos.myField)
50- // expect(sub_ipos.get('myField')).toEqual(value)
51- // expect(sub_ipos.myField).toEqual(value)
61+ // lodash equal to compare maps and sets
62+ expect ( _ . isEqualWith ( sub_ipos . myField , value , customizer ) ) . toEqual ( true )
63+ expect ( _ . isEqualWith ( sub_ipos . get ( 'myField' ) , value , customizer ) ) . toEqual ( true )
5264 }
5365 )
5466 } )
5567 }
56- })*/
68+ } )
0 commit comments