v2 / vlib / v / slow_tests / inout / printing_struct_with_thread_field.vv
44 lines · 41 sloc · 1.02 KB · 4f160b00e831c37a9b2a90432e6112d934b4c5c2
Raw
1// Video is the object containing all the information needed for
2// conversion to ascii.
3struct Video {
4pub:
5 // path may be URL or path on local file system.
6 path string
7 tmp_dir string
8 frame_count int
9 frame_format FrameFormat
10pub mut:
11 // TODO: once V fixes bug #19281 replace the type here
12 // with `thread !`. And the return type on the corresponding
13 // function that is spawned.
14 extract_frames_thread thread string
15 frames [][]u8
16 framerate f64 = 24.0
17}
18
19enum FrameFormat {
20 bmp
21 jpg
22}
23
24fn (video Video) extract_frames() string {
25 // try to extract frames os.execute()
26 // if os.execute() returns with an exit
27 // code other than 0, return an error.
28 if true {
29 return 'Failed to extract frames: os.execute() cmd output'
30 }
31 // do something else
32 return '1234'
33}
34
35fn main() {
36 mut video := Video{
37 path: '/path/to/some/mp4'
38 tmp_dir: '/tmp'
39 }
40 video.extract_frames_thread = spawn video.extract_frames()
41 println(video.extract_frames_thread.wait())
42 println(video)
43 flush_stdout()
44}
45