Skip to content

Commit

Permalink
Fix justFrom to handle Fun's with Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Oct 18, 2021
1 parent cc809da commit 6b83214
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions source/concurrency/sender.d
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ struct JustFromSender(Fun) {
import concurrency.receiver : setValueOrError;
static if (is(Value == void)) {
fun();
receiver.setValueOrError();
receiver.setValue();
} else
receiver.setValueOrError(fun());
receiver.setValue(fun());
}
}
Fun fun;
Expand Down Expand Up @@ -277,7 +277,7 @@ template canSenderThrow(Sender) {
else
void setValue(Sender.Value t) nothrow @safe @nogc {}
}
enum canSenderThrow = !__traits(compiles, Sender.init.connect(NoErrorReceiver()));
enum canSenderThrow = !__traits(compiles, Sender.init.connect(NoErrorReceiver()).start());
}

static assert( canSenderThrow!ThrowingSender);
Expand Down
11 changes: 8 additions & 3 deletions tests/ut/concurrency/sender.d
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ import core.atomic : atomicOp;
justFrom(() shared =>42).syncWait.value.should == 42;
}

@("justFrom.exception")
@safe unittest {
justFrom(() shared { throw new Exception("failure"); }).syncWait.isError.should == true;
}

@("delay")
@safe unittest {
import core.time : msecs;
Expand All @@ -241,7 +246,7 @@ import core.atomic : atomicOp;
auto prom = promise!int;
auto cont = prom.then((int i) => i * 2);
auto runner = justFrom(() shared => prom.fulfill(72));

whenAll(cont, runner).syncWait.value.should == 144;
}

Expand All @@ -251,7 +256,7 @@ import core.atomic : atomicOp;
auto prom = promise!int;
auto cont = prom.then((int i) => i * 2);
auto runner = justFrom(() shared => prom.fulfill(72));

whenAll(cont, cont, runner).syncWait.value.should == tuple(144, 144);
}

Expand All @@ -263,7 +268,7 @@ import core.atomic : atomicOp;

auto cont = prom.forwardOn(pool.getScheduler).then((int i) => i * 2);
auto runner = justFrom(() shared => prom.fulfill(72)).via(ThreadSender());

whenAll(cont, cont, runner).syncWait.value.should == tuple(144, 144);
}

Expand Down

0 comments on commit 6b83214

Please sign in to comment.