Stream<dynamic> executeSql(String statement) async* {
// Get the connection from the pool
var connection = await _connectionPool.connect() as postgres.Connection;
// Get the values
var values = connection.query(statement).map((row) => row.toList());
// Return the connection to the pool
connection.close();
yield* values;
}
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Future<Stream> getStream() async => _stream;
Stream transformStream() async* {
var stream = await getStream();
yield* stream.map(doMapping);
}
Good catch Natalie. That's something I missed when transitioning over to a Stream based API. I'm still getting an error from the VM about the Stream being in a bad state if I just comment out the close part to see if that was my problem.At a high level if you had something like this where the stream creation is deferred.
Future<Stream> getStream() async => _stream;
Stream transformStream() async* {
var stream = getStream();
yield* stream.map(doMapping);
}
Does that work as a general pattern for this? Or should I be avoiding the async* method when trying to accomplish something like this?
--
Good catch Natalie. That's something I missed when transitioning over to a Stream based API. I'm still getting an error from the VM about the Stream being in a bad state if I just comment out the close part to see if that was my problem.At a high level if you had something like this where the stream creation is deferred.
Future<Stream> getStream() async => _stream;
Stream transformStream() async* {
var stream = getStream();
yield* stream.map(doMapping);
}
--
import 'dart:async';
main() async{ Stream otherStream = transformStream(); await for(var stuff in otherStream){ print(stuff); }}
Stream transformStream() async* { var fooStream = await foo();
yield* fooStream.map((item)=>item*2);}
Future<Stream> foo() async{ return aStream(6).map((item)=>2*item);}
Stream aStream(n) async*{ int k = 1; while (k < n) yield k++;}
import 'dart:async';
Future<int> getMultiplier() async => 42;
Future<Stream> getStream() async => new Stream.fromIterable([0, 1, 2, 3, 4]);
Stream transformStream() async* {
var stream = await getStream();
yield* stream.map((value) => value * 2);;
}
Stream transformAgain() async* {
var multiplier = await getMultiplier();
yield* transformStream().map((value) => value * multiplier);
}
main(List<String> arguments) async {
await for (var value in transformAgain()) {
print(value);
}
}
List result = await connection.query("...").toList();
class Crayon {
String color;
int length;
}
List<Crayon> crayons = await connection
.query('select color, length from crayons')
.map((row) => new Crayon()
..color = row.color
..length = row.length)
.toList();
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.