hush-shell / hush

Hush is a unix shell based on the Lua programming language
MIT License
658 stars 23 forks source link

Async not working #44

Closed yonas closed 1 year ago

yonas commented 1 year ago

For the following code:

let handle = &{
  sleep 2;
  echo Hello world!;
}

# Do some other work before calling join.
# This may be printed before or after "Hello world!".
std.print("Doing some work...")

# This will wait until the block runs to completion, and will return it's result.
let result = handle.join()

std.assert(result == nil)

I'd expect Doing some work... to be printed, and then Hello world!. Instead, it sleeps without any output, and then prints:

Hello world!
Doing some work..

Hush 0.1.4 41adf74

gahag commented 1 year ago

That's because stdout is line-buffered, and std.print does not output a newline. Try switching to std.println and your example will work as expected.

yonas commented 1 year ago

@gahag Thanks :partying_face: