Async Loading
Part of the Examples. Load a .env file without blocking, using penvloadAsync.
Source: example/async_example.dart
// Run this example from the package root:
// dart run example/async_example.dart
//
// Async equivalent of penv_example.dart, for callers (e.g. server
// frameworks) that avoid synchronous file I/O.
//
// On first run there's no `.env` file yet, so penvloadAsync will create a
// placeholder at .env and throw EnvFileNotFoundException. Fill in the
// generated file and run again to see it load successfully.
// print() is fine in example scripts; avoid it in production code instead.
// ignore_for_file: avoid_print
import 'package:penv/penv.dart';
void main() async {
try {
final env = await penvloadAsync('.env');
print('Loaded ${env.length} variable(s):');
env.forEach((key, value) => print(' $key=$value'));
} on EnvFileNotFoundException catch (e) {
print(e);
}
}
Run it from the package root:
dart run example/async_example.dart