angel3_production 8.3.0 copy "angel3_production: ^8.3.0" to clipboard
angel3_production: ^8.3.0 copied to clipboard

Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel3.

example/main.dart

import 'dart:async';
import 'dart:isolate';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_production/angel3_production.dart';
import 'package:belatuk_pub_sub/belatuk_pub_sub.dart';

void main(List<String> args) {
  Runner('example', configureServer).run(args);
}

Future configureServer(Angel app) async {
  // Use the injected `pub_sub.Client` to send messages.
  var client = app.container.make<Client>();

  var greeting = 'Hello! This is the default greeting.';

  // We can listen for an event to perform some behavior.
  //
  // Here, we use message passing to synchronize some common state.
  var onGreetingChanged = await client.subscribe('greeting_changed');
  onGreetingChanged
      .cast<String>()
      .listen((newGreeting) => greeting = newGreeting);

  // Add some routes...
  app.get('/', (req, res) => 'Hello, production world!');

  app.get('/404', (req, res) {
    res.statusCode = 404;
    return res.close();
  });

  // Create some routes to demonstrate message passing.
  app.get('/greeting', (req, res) => greeting);

  // This route will push a new value for `greeting`.
  app.get('/change_greeting/:newGreeting', (req, res) {
    greeting = (req.params['newGreeting'] as String? ?? '');
    client.publish('greeting_changed', greeting);
    return 'Changed greeting -> $greeting';
  });

  // The `Runner` helps with fault tolerance.
  app.get('/crash', (req, res) {
    // We'll crash this instance deliberately, but the Runner will auto-respawn for us.
    Timer(const Duration(seconds: 3), Isolate.current.kill);
    return 'Crashing in 3s...';
  });
}
1
likes
150
points
134
downloads

Publisher

verified publisherdukefirehawk.com

Weekly Downloads

Helpers for concurrency, message-passing, rotating loggers, and other production functionality in Angel3.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

angel3_container, angel3_framework, args, belatuk_pub_sub, intl, io, logging

More

Packages that depend on angel3_production