The following code runs fine:
import 'package:pool/pool.dart';
main() async {
Pool pool = new Pool(1);
String s = await pool.withResource(() async => "Hi");
print(s);
}
However in strong mode I get the following errors:
dartanalyzer --strong bin/testpool.dart
Analyzing [bin/testpool.dart]...
[error] Couldn't infer type parameter 'T'; 'Future' must be of type 'String'. (/home/adam/dev/fp3/dart/yacht/bin/testpool.dart, line 6, col 25)
[error] The argument type '() → Future' can't be assigned to the parameter type '() → String'. (/home/adam/dev/fp3/dart/yacht/bin/testpool.dart, line 6, col 38)
2 errors found.
I believe this is because withResource allows callback to return a T or Future<T> but this is not reflected in the function signature. Probably the type of callback should be: FutureOr<T> callback().
The following code runs fine:
However in strong mode I get the following errors:
I believe this is because
withResourceallowscallbackto return aTorFuture<T>but this is not reflected in the function signature. Probably the type of callback should be:FutureOr<T> callback().