1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45use anyhow::Result;
6use fuchsia_async as fasync;
7use fuchsia_fuzzctl::{OutputSink, Writer};
8use futures::Future;
910/// Wraps a given `future` to display any returned errors using the given `writer`.
11pub fn create_task<F, O>(future: F, writer: &Writer<O>) -> fasync::Task<()>
12where
13F: Future<Output = Result<()>> + 'static,
14 O: OutputSink,
15{
16let writer = writer.clone();
17let wrapped = || async move {
18if let Err(e) = future.await {
19 writer.error(format!("task failed: {:?}", e));
20 }
21 };
22 fasync::Task::local(wrapped())
23}