Advertisement
Guest User

Background compilation server.

a guest
May 9th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import neko.io.Process;
  2. import neko.vm.Thread;
  3.  
  4. class HaxeServer
  5. {
  6.     public static var port = "4444";
  7.  
  8.     static var thread:Thread;
  9.  
  10.     public static function start()
  11.     {
  12.         #if haxe_209
  13.         if (thread == null)
  14.         {
  15.             Sys.println("Starting compilation server on port " + port);
  16.             thread = Thread.create(main);
  17.         }
  18.         #end
  19.     }
  20.  
  21.     public static function stop()
  22.     {
  23.         if (thread != null)
  24.         {
  25.             Sys.println("Killing compilation server on port " + port);
  26.             thread.sendMessage("kill");
  27.             thread = null;
  28.         }
  29.     }
  30.        
  31.     static function main()
  32.     {
  33.         var process = new Process("haxe", ["--wait", port]);
  34.         while (Thread.readMessage(false) != "kill") Sys.sleep(0.1);
  35.         process.kill();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement