task<T> function

Future<T> task<T>(
  1. FutureOr<T> computation(
    1. Drun
    )
)

Use this to create a new drun task.

  • computation Is an annoymous function, async or not, that runs your logic This function accepts a single parameter, an instance of Drun.

Usage example:

Future build() => task((drun) {
  drun.log('building project...');
});

Implementation

Future<T> task<T>(FutureOr<T> Function(Drun) computation) async {
  String prefix;
  var frame = Trace.current().frames[1];
  var rTask = reflectTask(frame);
  if (LogPrefix.hasMetadata(rTask.value)) {
    prefix = LogPrefix.fromMetadata(rTask.value).value;
  } else {
    prefix = rTask.key;
  }

  var d = Drun(prefix, _argv, _env, _options);
  var r = await computation(d);
  d.writeBufferedLogs();
  return r;
}