Browse Source

Added a busy sleep operation

Yentl Van Tendeloo 8 years ago
parent
commit
c1c0db877f
3 changed files with 20 additions and 0 deletions
  1. 1 0
      bootstrap/initial_code_manager.alc
  2. 18 0
      bootstrap/utils.alc
  3. 1 0
      interface/HUTN/includes/utils.alh

+ 1 - 0
bootstrap/initial_code_manager.alc

@@ -13,5 +13,6 @@ Void function __main():
 	exec(root["bootstrap/modelling.alc"]["initializers"])
 	exec(root["bootstrap/task_manager.alc"]["initializers"])
 	exec(root["bootstrap/core_algorithm.alc"]["initializers"])
+	exec(root["bootstrap/utils.alc"]["initializers"])
 	task_management()
 	return!

+ 18 - 0
bootstrap/utils.alc

@@ -53,3 +53,21 @@ String function JSON_print(model : Element):
 			result = result + "}"
 	result = result + "]"
 	return result!
+
+Void function sleep(timeout : Float):
+	// TODO Placeholder function for a real sleep operation
+	return!
+
+Element function input_timeout(timeout : Float):
+	Float start
+	start = time()
+
+	while (time() - start < timeout):
+		if (has_input()):
+			return input()!
+		else:
+			// Nothing to do, we should yield...
+			sleep(0.01)
+
+	return read_root()!
+

+ 1 - 0
interface/HUTN/includes/utils.alh

@@ -1 +1,2 @@
 String function JSON_print(model : Element)
+Element function input_timeout(timeout : Float)