vibe_spawn.dhover×100all
#!/usr/bin/env dub
/+ dub.sdl:
    name "vibe_spawn"
    dependency "vibe-core" version="2.14.0"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
    platforms "linux"
+/
import 
(package) core
core
.
(module) core.time

Module containing core time functionality, such as Duration (which represents a duration of time) or MonoTime (which represents a timestamp of the system's monotonic clock).

Various functions take a string (or strings) to represent a unit of time (e.g. convert!("days", "hours")(numDays)). The valid strings to use with such functions are "years", "months", "weeks", "days", "hours", "minutes", "seconds", "msecs" (milliseconds), "usecs" (microseconds), "hnsecs" (hecto-nanoseconds - i.e. 100 ns) or some subset thereof. There are a few functions that also allow "nsecs", but very little actually has precision greater than hnsecs.

Symbol Description
Types
Duration Represents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds).
TickDuration DEPRECATED Represents a duration of time in system clock ticks, using the highest precision that the system provides.
MonoTime Represents a monotonic timestamp in system clock ticks, using the highest precision that the system provides.
Functions
convert Generic way of converting between two time units.
dur Allows constructing a Duration from the given time units with the given length.
weeks days hours

minutes seconds msecs

usecs hnsecs nsecs | Convenience aliases for dur. | | abs | Returns the absolute value of a duration. |

From Duration
From TickDuration
From units
To Duration
tickDuration.to, std,conv!Duration()
dur!"msecs"(5) or 5.msecs()

| To TickDuration | duration.to, std,conv!TickDuration() |

  • | TickDuration.from!"msecs"(msecs) |

| To units | duration.total!"days" | tickDuration.msecs | convert!("days", "msecs")(msecs) |

Source

core/time.d

@copyrightCopyright 2010 - 2012@licenseBoost License 1.0.@authorsJonathan M Davis and Kato Shoichi
time
: msecs;
import
(package) std
std
.
(package) std.algorithm
algorithm
.
(module) std.algorithm.iteration

This is a submodule of std.algorithm. It contains generic iteration algorithms.

Function Name Description
cache Eagerly evaluates and caches another range's front.
lazyCache Lazily evaluates and caches another range's front, unlike cache.
cacheBidirectional As above, but also provides back and popBack.
chunkBy chunkBy!((a,b) => a[1] == b[1])([[1, 1], [1, 2], [2, 2], [2, 1]]) returns a range containing 3 subranges: the first with just [1, 1]; the second with the elements [1, 2] and [2, 2]; and the third with just [2, 1].
cumulativeFold cumulativeFold!((a, b) => a + b)([1, 2, 3, 4]) returns a lazily-evaluated range containing the successive reduced values 1, 3, 6, 10.
each each!writeln([1, 2, 3]) eagerly prints the numbers 1, 2 and 3 on their own lines.
filter filter!(a => a > 0)([1, -1, 2, 0, -3]) iterates over elements 1 and 2.
filterBidirectional Similar to filter, but also provides back and popBack at a small increase in cost.
fold fold!((a, b) => a + b)([1, 2, 3, 4]) returns 10.
group group([5, 2, 2, 3, 3]) returns a range containing the tuples tuple(5, 1), tuple(2, 2), and tuple(3, 2).
joiner joiner(["hello", "world!"], "; ") returns a range that iterates over the characters "hello; world!". No new string is created - the existing inputs are iterated.
map map!(a => a * 2)([1, 2, 3]) lazily returns a range with the numbers 2, 4, 6.
mean Colloquially known as the average, mean([1, 2, 3]) returns 2.
permutations Lazily computes all permutations using Heap's algorithm.
reduce reduce!((a, b) => a + b)([1, 2, 3, 4]) returns 10. This is the old implementation of fold.
splitWhen Lazily splits a range by comparing adjacent elements.
splitter Lazily splits a range by a separator, element predicate or whitespace.
substitute [1, 2].substitute(1, 0.1) returns [0.1, 2].
sum Same as fold, but specialized for accurate summation.
uniq Iterates over the unique elements in a range, which is assumed sorted.

Source

std/algorithm/iteration.d

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
iteration
:
(alias template) vibe_spawn.splitter = std.algorithm.iteration.splitter(alias pred = "a == b", Flag keepSeparators = No.keepSeparators, Range, Separator)(Range r, Separator s) if (is(typeof(binaryFun!pred(r.front, s)) : bool) && (hasSlicing!Range && hasLength!Range || isNarrowString!Range) && (is(ElementType!Range : Separator) || !(isForwardRange!Separator && (hasLength!Separator || isNarrowString!Separator))))

Lazily splits a range using an element or range as a separator. Separator ranges can be any narrow string type or sliceable range type.

Two adjacent separators are considered to surround an empty element in the split range. Use filter!(a => !a.empty) on the result to compress empty elements.

The predicate is passed to binaryFun and accepts any callable function that can be executed via pred(element, s).

Note

If splitting a string on whitespace and token compression is desired, consider using the ``splitter(r) overload.

Constraints

The predicate pred needs to accept an element of r and the separator s.

@parampred The predicate for comparing each element with the separator, defaulting to "a == b".@paramr The input range to be split. Must support slicing and .length or be a narrow string type.@params The element (or range) to be treated as the separator between range segments to be split.@paramkeepSeparators The flag for deciding if the separators are kept@returns

An input range of the subranges of elements between separators. If r is a forward range or bidirectional range, the returned range will be likewise. When a range is used a separator, bidirectionality isn't possible.

If keepSeparators is equal to Yes.keepSeparators the output will also contain the separators.

If an empty range is given, the result is an empty range. If a range with one separator is given, the result is a range with two empty elements.

@see
  • splitter for a version that splits using a regular expression defined separator.

  • split for a version that splits eagerly.

  • splitWhen, which compares adjacent elements instead of element against separator.

splitter
;
import
(package) std
std
.
(module) std.stdio
Category Symbols
File handles _popen File isFileHandle openNetwork stderr stdin stdout
Reading chunks lines readf readfln readln
Writing toFile write writef writefln writeln
Misc KeepTerminator LockType StdioException

Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio is publically imported when importing std.stdio.

There are three layers of I/O:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
stdio
:
(alias template) vibe_spawn.writeln = std.stdio.writeln(T...)(T args)

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
import
(package) vibe
vibe
.
(package) vibe.core
core
.
(module) vibe.core.core

This module contains the core functionality of the vibe.d framework.

@copyright© 2012-2020 Sönke Ludwig@licenseSubject to the terms of the MIT license, as written in the included LICENSE.txt file.@authorsSönke Ludwig
core
:
(alias template) vibe_spawn.runTask = vibe.core.core.runTask(ARGS...)(void delegate(ARGS) nothrow @safe task, auto ref ARGS args)

Runs a new asynchronous task.

task will be called synchronously from within the vibeRunTask call. It will continue to run until vibeYield() or any of the I/O or wait functions is called.

Note that the maximum size of all args must not exceed maxTaskParameterSize.

runTask
,
(alias) vibe_spawn.setTimer = vibe.core.core.Timer vibe.core.core.setTimer(core.time.Duration timeout, void delegate() nothrow @safe callback, bool periodic = false) nothrow @safe

Creates a new timer, that will fire callback after timeout

Timers can be be separated into two categories: one-off or periodic. One-off timers fire only once, after a specific amount of time, while periodic timer fire at a regular interval.

One-off_timers: One-off timers can be used for performing a task after a specific delay, or to schedule a time without interrupting the currently running code. For example, the following is a way to emulate a 'schedule' primitive, a way to schedule a task without starting it immediately (unlike runTask):

void handleRequest (scope HTTPServerRequest req, scope HTTPServerResponse res) {
	Payload payload = parse(req);
	if (payload.isValid())
	  // Don't immediately yield, finish processing the data and the query
	  setTimer(0.msecs, () => sendToPeers(payload));
	process(payload);
	res.writeVoidBody();
}

In this example, the server delays the network communication that will be performed by sendToPeers until after the request is fully processed, ensuring the client doesn't wait more than the actual processing time for the response.

Periodic timers

Periodic timers will trigger for the first time after timeout, then at best every timeout period after this. Periodic timers may be explicitly stopped by calling the Timer.stop() method on the return value of this function.

As timer are non-preemtive (see the "Preemption" section), user code does not need to compensate for time drift, as the time spent in the function will not affect the frequency, unless the function takes longer to complete than the timer.

Preemption

Like other events in Vibe.d, timers are non-preemptive, meaning that the currently executing function will not be interrupted to let a timer run. This is usually not a problem in server applications, as any blocking code will be easily noticed (the server will stop to handle requests), but might come at a surprise in code that doesn't handle request. If this is a problem, the solution is usually to either explicitly give control to the event loop (by calling yield) or ensuring operations are asynchronous (e.g. call functions from vibe.core.file instead of std.file).

Reentrancy

The event loop guarantees that the same timer will never be called more than once at a time. Hence, functions run on a timer do not need to be re-entrant, even if they execute for longer than the timer frequency.

@paramtimeout Determines the minimum amount of time that elapses before the timer fires.@paramcallback A delegate to be called when the timer fires. Can be null, in which case the timer will not do anything.@paramperiodic Speficies if the timer fires repeatedly or only once@returnsReturns a Timer object that can be used to identify and modify the timer.@seecreateTimer
setTimer
,
(struct) vibe.core.core.Timer

Represents a timer.

Timer
;
import
(package) vibe
vibe
.
(package) vibe.core
core
.
(module) vibe.core.process

Functions and structures for dealing with subprocesses and pipes.

This module is modeled after std.process, but provides a fiber-aware alternative to it. All blocking operations will yield the calling fiber instead of blocking it.

process
:
(alias) vibe_spawn.pipeProcess = vibe.core.process.ProcessPipes vibe.core.process.pipeProcess(scope string[] args, std.process.Redirect redirect = Redirect.all, const(string[string]) env = cast(const(string[string]))null, vibe.core.process.Config config = Config(Flags.none, null, null), scope vibe.core.path.GenericPath!(PosixPathFormat) workDir = GenericPath(null)) @trusted

Equivalent to std.process.pipeProcess``.

@returnsA struct containing the process and created pipes.@seespawnProcess, execute
pipeProcess
,
(enum) std.process.Redirect

Flags that can be passed to pipeProcess and pipeShell to specify which of the child process' standard streams are redirected. Use bitwise OR to combine flags.

Redirect
;
import
(package) vibe
vibe
.
(package) vibe.core
core
.
(module) vibe.core.stream

Generic stream interface used by several stream-like classes.

This module defines the basic (buffered) stream primitives. For concrete stream types, take a look at the vibe.stream`` package. The vibe.stream.operations module contains additional high-level operations on streams, such as reading streams by line or as a whole.

Note that starting with vibe-core 1.0.0, streams can be of either struct or class type. Any APIs that take streams as a parameter should use a template type parameter that is tested using the appropriate trait (e.g. isInputStream) instead of assuming the specific interface type (e.g. InputStream).

@copyright© 2012-2016 Sönke Ludwig@licenseSubject to the terms of the MIT license, as written in the included LICENSE.txt file.@authorsSönke Ludwig
stream
:
(enum) eventcore.driver.IOMode
IOMode
;
void
void D main()
main
()
{ auto
(local variable) vibe.core.process.ProcessPipes pipes
pipes
=
vibe.core.process.ProcessPipes vibe.core.process.pipeProcess(scope string[] args, std.process.Redirect redirect = Redirect.all, const(string[string]) env = cast(const(string[string]))null, vibe.core.process.Config config = Config(Flags.none, null, null), scope vibe.core.path.GenericPath!(PosixPathFormat) workDir = GenericPath(null)) @trusted

Equivalent to std.process.pipeProcess``.

@returnsA struct containing the process and created pipes.@seespawnProcess, execute
pipeProcess
(["sh", "-c", "echo one; echo two; exec sleep 30"],
(enum) std.process.Redirect

Flags that can be passed to pipeProcess and pipeShell to specify which of the child process' standard streams are redirected. Use bitwise OR to combine flags.

Redirect
.
(enum value) std.process.Redirect.stdout = 2

Redirect the standard input, output or error streams, respectively.

stdout
);
bool
(local variable) bool timedOut
timedOut
= false;
(struct) vibe.core.core.Timer

Represents a timer.

Timer
(local variable) vibe.core.core.Timer timer
timer
;
scope(exit)
(local variable) vibe.core.core.Timer timer
timer
.
void vibe.core.core.Timer.stop() nothrow @safe

Resets the timer and avoids any firing.

stop
();
// Manual line framing and streaming int
(local variable) int linesSeen
linesSeen
= 0;
(alias) object.string = string
string
(local variable) string pending
pending
;
auto
(local variable) vibe.core.task.Task reader
reader
=
vibe.core.task.Task vibe.core.core.runTask!()(void delegate() nothrow @safe task) nothrow @safe

Runs a new asynchronous task.

task will be called synchronously from within the vibeRunTask call. It will continue to run until vibeYield() or any of the I/O or wait functions is called.

Note that the maximum size of all args must not exceed maxTaskParameterSize.

runTask
(() nothrow {
try { ubyte[128]
(local variable) ubyte[128] buf
buf
;
while (!
(local variable) vibe.core.process.ProcessPipes pipes
pipes
.
(field) vibe.core.process.PipeInputStream vibe.core.process.ProcessPipes.stdout
stdout
.
bool vibe.core.process.PipeInputStream.empty() @property @safe
empty
) {
const
(local variable) const(ulong) n
n
=
(local variable) vibe.core.process.ProcessPipes pipes
pipes
.
(field) vibe.core.process.PipeInputStream vibe.core.process.ProcessPipes.stdout
stdout
.
ulong vibe.core.process.PipeInputStream.read(scope ubyte[] dst, eventcore.driver.IOMode mode) @safe
read
(
(local variable) ubyte[128] buf
buf
[],
(enum) eventcore.driver.IOMode
IOMode
.
(enum value) eventcore.driver.IOMode.once = 1

Process as much as possible with a single call

once
);
(local variable) string pending
pending
~= cast(const(char)[])
(local variable) ubyte[128] buf
buf
[0 ..
(local variable) const(ulong) n
n
];
import
(package) std
std
.
(module) std.string

String handling functions.

Category Functions
Searching
column
indexOf
indexOfAny
indexOfNeither
lastIndexOf
lastIndexOfAny
lastIndexOfNeither
Comparison
isNumeric
Mutation
capitalize
Pruning and Filling
center
chomp
chompPrefix
chop
detabber
detab
entab
entabber
leftJustify
outdent
rightJustify
strip
stripLeft
stripRight
wrap
Substitution
abbrev
soundex
soundexer
succ
tr
translate
Miscellaneous
assumeUTF
fromStringz
lineSplitter
representation
splitLines
toStringz
Objects of types string, wstring, and dstring are value types
and cannot be mutated element-by-element. For using mutation during building
strings, use char[], wchar[], or dchar[]. The xxxstring
types are preferable because they don't exhibit undesired aliasing, thus
making code more robust.

The following functions are publicly imported:

Module Functions
Publicly imported functions
std.algorithm
cmp, std,algorithm,comparison
count, std,algorithm,searching
endsWith, std,algorithm,searching
startsWith, std,algorithm,searching
std.array
join, std,array
replace, std,array
replaceInPlace, std,array
split, std,array
empty, std,array
std.format
format, std,format
sformat, std,format
std.uni
icmp, std,uni
toLower, std,uni
toLowerInPlace, std,uni
toUpper, std,uni
toUpperInPlace, std,uni
There is a rich set of functions for string handling defined in other modules.
Functions related to Unicode and ASCII are found in std.uni
and std.ascii, respectively. Other functions that have a
wider generality than just strings can be found in std.algorithm
and std.range.

Source

std/string.d

@seestd.algorithm and std.range for generic range algorithms , std.ascii for functions that work with ASCII strings , std.uni for functions that work with unicode strings@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
string
:
(alias template) indexOf = std.string.indexOf(Range)(Range s, dchar c, CaseSensitive cs = Yes.caseSensitive) if (isInputRange!Range && isSomeChar!(ElementType!Range) && !isSomeString!Range)

Searches for a character in a string or range.

    Params:
        s = string or InputRange of characters to search for `c` in
        c = character to search for in `s`
        startIdx = index to a well-formed code point in `s` to start
            searching from; defaults to 0
        cs = specifies whether comparisons are case-sensitive
            (`Yes.caseSensitive`) or not (`No.caseSensitive`).

    Returns:
        If `c` is found in `s`, then the index of its first occurrence is
        returned. If `c` is not found or `startIdx` is greater than or equal to
        `s.length`, then -1 is returned. If the parameters are not valid UTF,
        the result will still be either -1 or in the range [`startIdx` ..
        `s.length`], but will not be reliable otherwise.

    Throws:
        If the sequence starting at `startIdx` does not represent a well-formed
        code point, then a $(REF UTFException, std,utf) may be thrown.

    See_Also: $(REF countUntil, std,algorithm,searching)
indexOf
;
for (auto
(local variable) long end
end
=
(local variable) string pending
pending
.
long std.string.indexOf!char(scope const(char)[] s, dchar c, std.typecons.Flag!"caseSensitive" cs = Flag.yes) pure nothrow @nogc @safe

Searches for a character in a string or range.

@params string or InputRange of characters to search for c in@paramc character to search for in s@paramstartIdx index to a well-formed code point in s to start searching from; defaults to 0@paramcs specifies whether comparisons are case-sensitive (Yes.caseSensitive) or not (No.caseSensitive).@returnsIf c is found in s, then the index of its first occurrence is returned. If c is not found or startIdx is greater than or equal to s`.length`, then -1 is returned. If the parameters are not valid UTF, the result will still be either -1 or in the range [`startIdx` .. s.length], but will not be reliable otherwise.@throwsIf the sequence starting at startIdx does not represent a well-formed code point, then a UTFException may be thrown.@seecountUntil
indexOf
('\n'); end >= 0; end = pending.indexOf('\n')) {
auto
(local variable) string line
line
=
(local variable) string pending
pending
[0 ..
(local variable) long end
end
];
(local variable) string pending
pending
=
(local variable) string pending
pending
[
(local variable) long end
end
+ 1 .. $];
if (
(local variable) string line
line
.
(field) ulong string.length
length
) {
assert(
(local variable) string line
line
== (
(local variable) int linesSeen
linesSeen
== 0 ? "one" : "two"));
void std.stdio.writeln!(string, string)(string __param_0, string __param_1) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("line: ",
(local variable) string line
line
);
++
(local variable) int linesSeen
linesSeen
;
if (
(local variable) int linesSeen
linesSeen
== 2)
(local variable) vibe.core.core.Timer timer
timer
=
vibe.core.core.Timer vibe.core.core.Timer.opAssign(vibe.core.core.Timer p) nothrow return ref @trusted
setTimer
(100.msecs, () nothrow {
(local variable) bool timedOut
timedOut
= true;
try
(local variable) vibe.core.process.ProcessPipes pipes
pipes
.
(field) vibe.core.process.Process vibe.core.process.ProcessPipes.process
process
.
void vibe.core.process.Process.kill() @safe

Kill the process.

By default on Linux this sends SIGTERM to the process.

@paramsignal Optional parameter for the signal to send to the process.
kill
(); catch (
(class) object.Exception

The base class of all errors that are safe to catch and handle.

In principle, only thrown objects derived from this class are safe to catch inside a catch block. Thrown objects not derived from Exception represent runtime errors that should not be caught, as certain runtime guarantees may not hold, making it unsafe to continue program execution.

Examples

bool gotCaught;
try
{
    throw new Exception("msg");
}
catch (Exception e)
{
    gotCaught = true;
    assert(e.msg == "msg");
}
assert(gotCaught);
Exception
(local variable) object.Exception e
e
) { assert(false,
(local variable) object.Exception e
e
.
(field) string object.Throwable.msg

A message describing the error.

msg
); }
}); } } } } catch (
(class) object.Exception

The base class of all errors that are safe to catch and handle.

In principle, only thrown objects derived from this class are safe to catch inside a catch block. Thrown objects not derived from Exception represent runtime errors that should not be caught, as certain runtime guarantees may not hold, making it unsafe to continue program execution.

Examples

bool gotCaught;
try
{
    throw new Exception("msg");
}
catch (Exception e)
{
    gotCaught = true;
    assert(e.msg == "msg");
}
assert(gotCaught);
Exception
(local variable) object.Exception e
e
) { assert(false,
(local variable) object.Exception e
e
.
(field) string object.Throwable.msg

A message describing the error.

msg
); }
}); const
(local variable) const(int) status
status
=
(local variable) vibe.core.process.ProcessPipes pipes
pipes
.
(field) vibe.core.process.Process vibe.core.process.ProcessPipes.process
process
.
int vibe.core.process.Process.wait() @safe

Wait for the process to exit, allowing other fibers to continue in the meantime.

@paramtimeout Optionally wait until a timeout is reached.@returnsThe exit code of the process. If a timeout is given and reached, a null value is returned.
wait
();
(local variable) vibe.core.task.Task reader
reader
.
void vibe.core.task.Task.join() @trusted
join
();
assert(
(local variable) int linesSeen
linesSeen
== 2);
assert(
(local variable) string pending
pending
.
(field) ulong string.length
length
== 0 &&
(local variable) const(int) status
status
== -15);
assert(
(local variable) bool timedOut
timedOut
);
void std.stdio.writeln!string(string __param_0) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("exited: timedOut, signaled by 15");
void std.stdio.writeln!string(string __param_0) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("end: timedOut, reap: reaped");
}