~schnouki/watch_tabnine

77c05df3f2e7319cec3ac3b9c1e9041c83f7a4b1 — Thomas Jost 5 years ago bfb802b master
Don't crash when processes change too fast
1 files changed, 13 insertions(+), 3 deletions(-)

M watch_tabnine.d
M watch_tabnine.d => watch_tabnine.d +13 -3
@@ 93,17 93,27 @@ class Process
    }
}

T swallow(T)(lazy T exp, T dVal)
{
    try {
        return exp();
    }
    catch (Exception e) {
        return dVal;
    }
}

void run()
{
    auto now = Clock.currTime();
    writef!"%s: running\n"(now.toISOExtString());

    auto procs = dirEntries("/proc", SpanMode.shallow, false)
        .filter!(a => a.isDir)
        .filter!(a => swallow(a.isDir(), false))
        .map!(a => baseName(a.name))
        .filter!(a => isNumeric(a))
        .map!(a => new Process(to!uint(a)))
        .filter!(a => a.name == TabNineExecutableName)
        .map!(a => swallow(new Process(to!uint(a)), null))
        .filter!(a => a !is null && a.name == TabNineExecutableName)
        .filter!(a => a.isTooBig)
        .array;