streamjoin 1.0.0 copy "streamjoin: ^1.0.0" to clipboard
streamjoin: ^1.0.0 copied to clipboard

A type-safe Dart library for joining multiple streams into a single stream.

example/README.md

Stream<String> status() async* {
  while (true) {
    yield 'off';
    await Future.delayed(const Duration(seconds: 2));
    yield 'on';
    await Future.delayed(const Duration(seconds: 2));
  }
}

Stream<int> counter() async* {
  var counter = 0;
  await Future.delayed(const Duration(seconds: 1));
  while (true) {
    yield counter++;
    await Future.delayed(const Duration(seconds: 2));
  }
}

import 'package:streamjoin/streamjoin.dart';

void main() async {
  await for (final (status, counter) in (status(), counter()).join) {
    print('status: $status, counter: $counter');
  }
}

or

import 'package:flutter/material.dart';
import 'package:streamjoin/streamjoin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: StreamBuilder(
          stream: (status(), counter()).join,
          builder: (context, snapshot) {
            final (status, counter) = snapshot.data ?? (null, null);
            return Center(child: Text('status: $status, counter: $counter'));
          },
        ),
      ),
    );
  }
}

status: off, counter: null
status: off, counter: 0
status: on, counter: 0
status: on, counter: 1
...
1
likes
160
pub points
17%
popularity

Publisher

verified publisherinteracsion.dev

A type-safe Dart library for joining multiple streams into a single stream.

Repository (GitHub)
View/report issues

Topics

#util #streams #extension #async

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on streamjoin