Skip to content
This repository was archived by the owner on Oct 12, 2024. It is now read-only.

Commit a833d59

Browse files
committed
Feature update
1 parent c47a9ac commit a833d59

File tree

5 files changed

+143
-1
lines changed

5 files changed

+143
-1
lines changed

lib/src/_all_src.g.dart

+2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ export 'web_friendly/app/rec.dart';
2222
export 'web_friendly/app/screen_calculator.dart';
2323
export 'web_friendly/app/single_service.dart';
2424
export 'web_friendly/http_service.dart';
25+
export 'web_friendly/http/t_http_function_result.dart';
2526
export 'web_friendly/patterns/recursive_replace.dart';
2627
export 'web_friendly/patterns/replace_patterns.dart';
2728
export 'web_friendly/second_to_ninth_element_on_iterable_extension.dart';
2829
export 'web_friendly/stream_to_future.dart';
30+
export 'web_friendly/streams/polling_stream.dart';
2931
export 'web_friendly/time/date_time.dart';
3032
export 'web_friendly/time/duration_formatted_english.dart';
3133
export 'web_friendly/tuples.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// 🇽🇾🇿 & Dev
5+
//
6+
// Licensing details are in the LICENSE file in the root directory.
7+
//
8+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
9+
//.title~
10+
11+
import 'package:http/http.dart' as http;
12+
13+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
typedef THttpFunctionResult = ({http.Response? response, bool success});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// 🇽🇾🇿 & Dev
5+
//
6+
// Licencing details are in the LICENSE file in the root directory.
7+
//
8+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
9+
//.title~
10+
11+
import 'dart:async';
12+
13+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
Stream<T> pollingStream<T>(
16+
Future<T> Function() callback,
17+
Duration interval,
18+
) {
19+
final controller = StreamController<T>();
20+
Future<void> $startPolling() async {
21+
try {
22+
while (!controller.isClosed) {
23+
try {
24+
final result = await callback();
25+
controller.add(result);
26+
} catch (e) {
27+
controller.addError(e);
28+
}
29+
await Future.delayed(interval);
30+
}
31+
} catch (e) {
32+
if (!controller.isClosed) {
33+
controller.addError(e);
34+
controller.close();
35+
}
36+
}
37+
}
38+
39+
$startPolling();
40+
41+
return controller.stream;
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//.red
2+
// Not needed. There are better ways to do this. I kept this here because it's interesting.
3+
//.red~
4+
5+
// //.title
6+
// // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
7+
// //
8+
// // 🇽🇾🇿 & Dev
9+
// //
10+
// // Licencing details are in the LICENSE file in the root directory.
11+
// //
12+
// // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
13+
// //.title~
14+
15+
// import 'dart:async';
16+
17+
// // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
18+
19+
// class StreamMapper<A> {
20+
// //
21+
// //
22+
// //
23+
24+
// final Stream<A> stream;
25+
26+
// //
27+
// //
28+
// //
29+
30+
// const StreamMapper(this.stream);
31+
32+
// //
33+
// //
34+
// //
35+
36+
// StreamMapper<B> map<B>(
37+
// Stream<B> Function(A result1) mapper,
38+
// ) {
39+
// return StreamMapper(
40+
// _firstToSecondStream(this.stream, mapper),
41+
// );
42+
// }
43+
// }
44+
45+
// // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
46+
47+
// /// Combines two streams into one. The first stream is used to create the second stream.
48+
// Stream<B> _firstToSecondStream<A, B>(
49+
// Stream<A> stream1,
50+
// Stream<B> Function(A result1) stream2Creator,
51+
// ) {
52+
// late StreamController<B> controller;
53+
// StreamSubscription<A?>? subscription1;
54+
// StreamSubscription<B>? subscription2;
55+
// controller = StreamController<B>(
56+
// onListen: () {
57+
// subscription1 = stream1.asyncMap((e) async {
58+
// await subscription2?.cancel();
59+
// return e;
60+
// }).listen(
61+
// (result1) {
62+
// final stream2 = stream2Creator(result1!);
63+
// subscription2 = stream2.listen(
64+
// controller.add,
65+
// onError: controller.addError,
66+
// onDone: controller.close,
67+
// );
68+
// subscription1?.cancel();
69+
// },
70+
// onError: controller.addError,
71+
// onDone: controller.close,
72+
// cancelOnError: true,
73+
// );
74+
// },
75+
// onCancel: () => Future.wait(
76+
// [
77+
// subscription2?.cancel(),
78+
// subscription1?.cancel(),
79+
// ].nonNulls,
80+
// ),
81+
// );
82+
// return controller.stream;
83+
// }

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
name: xyz_utils
1414
description: This package provides a set of utilities that are commonly used in Dart apps. It is also the foundation for other packages in the XYZ ecosystem.
1515
repository: https://github.com/robmllze/xyz_utils
16-
version: 0.56.1
16+
version: 0.57.0
1717

1818
## -----------------------------------------------------------------------------
1919

0 commit comments

Comments
 (0)