aboutsummaryrefslogtreecommitdiffhomepage
path: root/notes/output_streams.txt
blob: 8c25a042cdd0db79e861ad9c4422724a59b27239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

Text output
===========

Idea: Make output streams look like strings!
Advantages:
+ Easy to use / understand
+ Can be buffered
+ Can be outputted when buffer is full
+ C++ programmers will find it familiar ("os <<" vs "os +=")
Disadvantage:
- Does not support translation properly!

Failures to flush the buffer when performing an += operation causes an
asynchronous failure. Failures could be configured in 3 modes:
1. Cause the whole "isolated arena" to fail (typically the whole process, or
   the request in servers), just like a divison by zero or integer overflow.
2. Defer the error until .close() or .flush() is called
   (and perhaps have a .signal_errors() function)
3. Ignore the error.

These 3 may need to have separate types, but "converting" to a lower number
is fine. In case 1, a "risky" block should be required at both the += and
close/flush calls, and in case 2, only in the close/flush calls.

Example:

    func write_stuff(arena, string name, int numbers)
    {
        own OutputStream os = .open_console_out(arena)
        os += "Hello " + name + "\n"
        for int i in .range(0, numbers-1) {
            os += i + ": Test\n"
        }
        os.close()
    }