angel_production 1.0.0-alpha.1 copy "angel_production: ^1.0.0-alpha.1" to clipboard
angel_production: ^1.0.0-alpha.1 copied to clipboard

outdated

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

example/main.dart

import 'dart:async';
import 'dart:isolate';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_production/angel_production.dart';
import 'package:pub_sub/pub_sub.dart' as pub_sub;

main(List<String> args) => new Runner('example', configureServer).run(args);

Future configureServer(Angel app) async {
  // Use the injected `pub_sub.Client` to send messages.
  var client = app.container.make<pub_sub.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!');

  // 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.
    new Timer(const Duration(seconds: 3), Isolate.current.kill);
    return 'Crashing in 3s...';
  });
}
1
likes
0
pub points
21%
popularity

Publisher

verified publisherangel-dart.dev

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

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

angel_container, angel_framework, args, io, logging, pub_sub

More

Packages that depend on angel_production