2 Mixed Unix-style and Racket Object Pipelines
(require shell/mixed-pipeline) | package: shell-pipeline |
2.1 shell/mixed-pipeline stability
Unstable features are flagged in the documentation. There are few of them.
2.2 shell/mixed-pipeline guide
This is the runtime library behind Pipeline Macro Library.
Everything from this module is also provided by the pipeline-macro library. This library is primarily of interest for its functions for inspecting pipeline objects that represent running (or finished) pipelines.
2.3 shell/mixed-pipeline reference
procedure
(run-mixed-pipeline member ... [ #:in in #:out out #:err err #:strictness strictness #:lazy-timeout lazy-timeout #:return-pipeline-object return-pipeline-object #:bg bg]) → any/c
member :
(or/c unix-pipeline-member-spec? object-pipeline-member-spec? composite-pipeline-member-spec?) in : (or/c input-port? false/c) = (open-input-string "") out : any/c = default-output-transformer
err :
(or/c port? false/c path-string-symbol? file-redirection-spec? special-redirect?) = stderr-capture-redirect strictness : (or/c 'strict 'lazy 'permissive) = 'lazy lazy-timeout : real? = 1 return-pipeline-object : any/c = #f bg : any/c = #f
The pipeline members are run by a driver thread until they are completed. Object pipeline members are run serially, while unix pipeline members are run in parallel. When it is time to run a unix pipeline member, all unix members adjacent in a pipeline (including within composite pipeline members) are run in parallel with run-subprocess-pipeline. If they are followed by an object member, the output port of the last unix member is passed to the object member and it starts running immediately.
If either bg or return-pipeline-object are non-false values, then the pipeline object itself is returned. Otherwise the result of the final pipeline member is returned. If there is an error in the pipeline and either bg or return-pipeline-object are true, the pipeline object is still returned (and can be checked for errors), otherwise the exception encountered in the pipeline is raised. If bg is non-false, then run-mixed-pipeline returns the pipeline object immediately, otherwise run-mixed-pipeline waits for the whole pipeline to finish before returning a value.
The in, out, and err options only affect unix pipeline members. Specifically, if the pipeline begins with a unix member, in is used as its initial input port. For all unix members that don’t specify an error port, err is used as their default. If the last member of the pipeline is a unix member, then out is used either as its output port, OR as a function that is appended to the pipeline to consume the final output port and produce some object.
Note: if you use a transformer function on the output, the transformer should close the port!
The strictness and lazy-timeout options are also passed through to run-subprocess-pipeline, and only affect unix pipeline members.
This function is run by run-pipeline macro, and otherwise this function should probably only be used if you want to write a replacement for the pipeline-macro library.
The semantics of bg is not stable.
2.3.1 Specifying Mixed Pipelines
procedure
(object-pipeline-member-spec? spec) → boolean?
spec : any/c
procedure
(object-pipeline-member-spec proc) → boolean?
proc : procedure?
procedure
(unix-pipeline-member-spec? spec) → boolean?
spec : any/c
procedure
(unix-pipeline-member-spec argl [ #:err err #:success success-pred]) → pipeline-member-spec? argl : any/c
err :
(or/c port? false/c path-string-symbol? file-redirection-spec? special-redirect?) = hidden-default-value
success-pred : (or/c false/c procedure? (listof any/c)) = hidden-default-value
procedure
(composite-pipeline-member-spec? spec) → boolean?
spec : any/c
procedure
(composite-pipeline-member-spec spec-list)
→ composite-pipeline-member-spec?
spec-list :
(listof (or/c unix-pipeline-member-spec? object-pipeline-member-spec? composite-pipeline-member-spec?))
2.3.2 Inspecting Mixed Pipelines
Also, pipelines are synchronizable with the sync function.
procedure
(pipeline-success? pline) → boolean?
pline : pipeline?
This also waits for the pipeline to finish if it hasn’t yet.
procedure
(pipeline-wait pline) → any/c
pline : pipeline?
(pipeline-wait pline) is essentially the same as (sync pline).
procedure
(pipeline-return pline) → any/c
pline : pipeline?
This also waits for the pipeline to finish if it hasn’t yet.