Tue 27 Aug 00:14:56 CEST 2024
This commit is contained in:
		
							parent
							
								
									a98e8e98ba
								
							
						
					
					
						commit
						a1e9f488c1
					
				
							
								
								
									
										47
									
								
								test/test-fork.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								test/test-fork.js
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,47 @@
 | 
			
		|||
function master(xy) {
 | 
			
		||||
  this.data=xy;
 | 
			
		||||
  this.z=0;
 | 
			
		||||
  this.child=null;
 | 
			
		||||
  this.act = {
 | 
			
		||||
    start : () => {
 | 
			
		||||
      log('start');
 | 
			
		||||
      this.child = fork({
 | 
			
		||||
        data:{
 | 
			
		||||
          x:random(1,50),
 | 
			
		||||
          y:random(1,50)
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    },
 | 
			
		||||
    compA: () => {
 | 
			
		||||
      this.z=this.data.x+this.data.y;
 | 
			
		||||
      log('z='+this.z)
 | 
			
		||||
    },
 | 
			
		||||
    compB: () => {
 | 
			
		||||
      this.z=this.data.x*this.data.y;
 | 
			
		||||
      log('z='+this.z); 
 | 
			
		||||
    },
 | 
			
		||||
    end : () => {
 | 
			
		||||
      log(keys(this))
 | 
			
		||||
      log(keys(this.act))
 | 
			
		||||
      log(keys(this.trans))
 | 
			
		||||
      if (this.on) log(keys(this.on))
 | 
			
		||||
      kill()
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  this.trans = {
 | 
			
		||||
    start:() => {
 | 
			
		||||
      return this.data.x<10 && this.data.y<10?compB:compA
 | 
			
		||||
    },
 | 
			
		||||
    compA:end,
 | 
			
		||||
    compB:end
 | 
			
		||||
  }
 | 
			
		||||
  this.on = {
 | 
			
		||||
    SIG1: () => {
 | 
			
		||||
      log('got SIG1')
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  this.next=start
 | 
			
		||||
}
 | 
			
		||||
compile(master)
 | 
			
		||||
create('master',{x:5,y:7})
 | 
			
		||||
start()
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user