1 module tagion.utils.pretend_safe_concurrency;
2 
3 private import concurrency = std.concurrency;
4 
5 import core.time : Duration;
6 import std.meta : allSatisfy;
7 import std.traits : isSafe;
8 
9 /** @brief File contains functions of std.concurrency wrapped in @trusted
10  *         to use them in @safe code
11  */
12 
13 public import std.concurrency : Tid,
14     ThreadInfo,
15     OwnerTerminated,
16     TidMissingException,
17     thisTid,
18     PriorityMessageException,
19     MailboxFull,
20     OnCrowding,
21     MessageMismatch,
22     Variant;
23 
24 void setMaxMailboxSize(Tid tid, size_t messages, OnCrowding doThis) @trusted {
25     concurrency.setMaxMailboxSize(tid, messages, doThis);
26 }
27 
28 void unregister(string name) @trusted {
29     concurrency.unregister(name);
30 }
31 
32 void send(Args...)(Tid tid, Args args) @trusted {
33     concurrency.send(tid, args);
34 }
35 
36 void prioritySend(Args...)(Tid tid, Args args) @trusted {
37     concurrency.prioritySend(tid, args);
38 }
39 
40 void receive(Args...)(Args args) @trusted if (allSatisfy!(isSafe, Args)) {
41     concurrency.receive(args);
42 }
43 
44 auto receiveOnly(T...)() @trusted {
45     return concurrency.receiveOnly!T;
46 }
47 
48 bool receiveTimeout(Args...)(Duration duration, Args ops) @trusted if (allSatisfy!(isSafe, Args)) {
49     return concurrency.receiveTimeout(duration, ops);
50 }
51 
52 Tid ownerTid() @trusted {
53     return concurrency.ownerTid;
54 }
55 
56 Tid spawn(F, Args...)(F fn, Args args) @trusted {
57     return concurrency.spawn(fn, args);
58 }
59 
60 Tid locate(string name) @trusted {
61     return concurrency.locate(name);
62 }
63 
64 bool register(string name, Tid tid) @trusted {
65     return concurrency.register(name, tid);
66 }