;; async returns a 'future'
;;
;; see examples/core/xthread.xtm for usage
;;
;; async -> 0 args
;;
(bind-func async:[[!a]*,[!a]*]*
(lambda (f)
;; (println "zone in:" (peek_zone))
(let ((z1 (push_new_zone 4096))
(res (convert null))
(running:i1 #t)
(finished:i1 #f)
(ff (lambda ()
(push_zone z1)
(set! res (f))
(set! finished #t)
(pop_zone)
void))
(thread null))
(pop_zone)
(set! thread (thread_fork (get_native_fptr thread_native_call) (cast ff i8*)))
(lambda ()
(thread_join thread)
(let ((r2 (zcopy res z1 (llvm_peek_zone_stack))))
(llvm_zone_destroy z1)
(thread_destroy thread)
r2)))))