with `.async`: run in a fresh child process instead of an in-VM fiber (slower spawn, no closure capture, full process isolation)
lazy
with `.async`: queue the task without running it; first scheduler tick (`wait`/`pause`/...) starts it
as
:string
with `.async`: tag the resulting `:task` with a symbolic name (shown in `print` / `inspect` for debugging)
timeout
:integer, :quantity
with a `:task` arg: give up draining after the given duration (ms by default; accepts time `:quantity` like `2:s`); returns an `:error` value on timeout and leaves the task pending
Returns
:task
:any
Examples
copy
do "print 123" ; 123
copy
do [
x: 3
print ["x =>" x] ; x => 3
]
copy
print do "https://raw.githubusercontent.com/arturo-lang/arturo/master/examples/projecteuler/euler1.art"
; 233168
; Importing modules
; let's say you have a 'module.art' with this code:
;
; pi: 3.14
;
; hello: $[name :string] [
; print ["Hello" name]
;]
do relative "module.art"
print pi
; 3.14
do [
hello "John Doe"
; Hello John Doe
]
; Note: always use imported functions inside a 'do block
; since they need to be evaluated beforehand.
; On the other hand, simple variables can be used without
; issues, as 'pi in this example
copy
; concurrent evaluation, returns a `:task`
x: 10
t: do.async [ x + 32 ]
print wait t ; 42
copy
; ⚠ closure capture is shallow-copy: writes do NOT leak back
u: 1
wait do.async [ u: 99 ]
print u ; 1
copy
; subprocess flavor: fresh VM, no closure capture
t: do.async.isolated [ print "fresh VM" ]
wait t