io.alc 766 B

12345678910111213141516171819202122232425262728293031323334353637
  1. include "io.alh"
  2. include "primitives.alh"
  3. // Placeholder for internal functions
  4. Element function __input()
  5. Void function __output(value : Element)
  6. Element function input():
  7. while (bool_not(has_input())):
  8. interruptable_sleep(0.5)
  9. Element inp
  10. inp = __input()
  11. return inp!
  12. Void function output(value : Element):
  13. __output(value)
  14. return!
  15. Element function input_timeout(timeout : Float):
  16. Float start
  17. start = time()
  18. // Do this first, such that we will always get at least the chance to push input in
  19. if (has_input()):
  20. return input()!
  21. // Now just try this again from time to time
  22. while (time() - start < timeout):
  23. if (has_input()):
  24. return input()!
  25. else:
  26. // Nothing to do, we should yield...
  27. interruptable_sleep(0.1)
  28. return read_root()!