Hacker News new | ask | show | jobs
by donri 4782 days ago
This should be the translation:

    for d in *
        test -d $d
        or continue
        begin
            cd $d
            time-consuming-task-1
            time-consuming-task-2
        end &
    end
However it errors; seems you can't do `end &`. Probably a bug; I'll report it. When fixed, I imagine we could actually do it even better with fish:

    for d in *
        if test -d $d
            cd $d
            time-consuming-task-1
            time-consuming-task-2
        end &
    end
1 comments

Fish currently does not support executing shell functions or commands in the background with &, only external programs. This is a known omission, but the best way to fix it is to make the shell interpreter code thread safe so we can actually write multithreaded shell code. Currently fish only uses threads for potentially blocking i/o operations. But implementing this is quite a bit of work and has not been done yet.

Having said that, `enc &` erroring is indeed a bug, expected behavior would be to run the `begin ... end &` block in the foreground anyway.