go_flow 1.0.2 copy "go_flow: ^1.0.2" to clipboard
go_flow: ^1.0.2 copied to clipboard

A simple implementation of go-lang's deffer statement, bringing it into dart-lang

example/go_flow_example.dart

// ignore_for_file: avoid_print

import 'dart:io';

import 'package:go_flow/go_flow.dart';

Future<void> main() async {
  final testFile = File('example/test.log');
  syncWrite(testFile);
  await asyncWrite(testFile);
}

void syncWrite(File file) => syncGoFlow(
      (defer) {
        final io = file.openSync(mode: FileMode.append);
        defer(
          (result, recover) {
            final err = recover<FileSystemException>();
            if (err != null) {
              print('there was an error in request');
            }
            io.closeSync();
          },
        );
        io.writeStringSync('text');
      },
    );
Future<void> asyncWrite(File file) => asyncGoFlow(
      (defer) async {
        final io = await file.open(mode: FileMode.append);
        defer(
          (result, recover) async {
            final err = recover<FileSystemException>();
            if (err != null) {
              print('there was an error in request');
            }
            await io.close();
          },
        );
        await io.writeString('text');
      },
    );
2
likes
160
points
129
downloads

Publisher

verified publishermoti.monster

Weekly Downloads

A simple implementation of go-lang's deffer statement, bringing it into dart-lang

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on go_flow