MongoDartとFutureを使って関数を開発しました。Dart SDK 0.2.9を使用して実行すると、例外なく動作します。
import 'model.dart';
import 'dart:json';
import 'package:mongo_dart/mongo_dart.dart';
class LinkDAO {
DbCollection _links;
Future<List> getAllLinks(){
var completer = new Completer<List>();
Db db = new Db("mongodb://127.0.0.1:27017/dart-link");
List linkList = new List();
_links = db.collection("links");
db.open().chain((c){
return _links.find({}).each(
(link){
print("[${link['link']}]:[${link['readed']}]:[${link['title']}]");
linkList.add(new Link(link['link'],link['title'],link['readed']));
print('lenght ${linkList.length}');
}).chain((link)=>completer.complete(linkList));
}).then((dummy){
db.close();
});
return completer.future;
}
}
void main(){
Future<List> futureResult=new LinkDAO().getAllLinks();
futureResult.then((result){
print("final!!! -> ${result.length}");
});
}
これはLinkクラスです
library models;
class Link {
String title;
String link;
bool readed;
Link(this.title,this.link,this.readed);
}
リリース0.2.10へのアップデート後、同じ関数が次の例外を生成します。
[assas]:[true]:[sasas]
lenght 1
[assas]:[true]:[sasas]
lenght 2
final!!! -> 2
Unhandled exception:
NoSuchMethodError : method not found: 'handleException'
Receiver: null
Arguments: [Closure: _FutureImpl@0x36924d72<T>(dynamic, dynamic) => dynamic]
#0 Object._noSuchMethod (dart:core-patch:1360:3)
#1 Object.noSuchMethod (dart:core-patch:1361:25)
#2 _FutureImpl._forwardException (bootstrap:935:27)
#3 _FutureImpl._forward (bootstrap:931:22)
#4 _FutureImpl.chain.<anonymous closure> (bootstrap:903:15)
#5 _FutureImpl._complete (bootstrap:840:19)
#6 _FutureImpl._complete (bootstrap:848:5)
#7 _FutureImpl._setValue (bootstrap:862:14)
#8 _CompleterImpl.complete (bootstrap:949:26)
#9 Cursor._nextEach.<anonymous closure> (package:mongo_dart/src/database/cursor.dart:112:30)
#10 _FutureImpl.then (bootstrap:792:16)
#11 Cursor._nextEach (package:mongo_dart/src/database/cursor.dart:109:22)
#12 Cursor._nextEach.<anonymous closure> (package:mongo_dart/src/database/cursor.dart:115:18)
#13 _FutureImpl.then (bootstrap:792:16)
#14 Cursor._nextEach (package:mongo_dart/src/database/cursor.dart:109:22)
#15 Cursor._nextEach.<anonymous closure> (package:mongo_dart/src/database/cursor.dart:115:18)
#16 _FutureImpl._complete (bootstrap:840:19)
#17 _FutureImpl._complete (bootstrap:848:5)
#18 _FutureImpl._setValue (bootstrap:862:14)
#19 _CompleterImpl.complete (bootstrap:949:26)
#20 Cursor.nextObject.<anonymous closure> (package:mongo_dart/src/database/cursor.dart:74:28)
#21 _FutureImpl._complete (bootstrap:840:19)
#22 _FutureImpl._complete (bootstrap:848:5)
#23 _FutureImpl._setValue (bootstrap:862:14)
#24 _CompleterImpl.complete (bootstrap:949:26)
#25 Connection._receiveData._receiveData (package:mongo_dart/src/database/connection.dart:84:27)
#26 _SocketBase._multiplex (dart:io-patch:410:26)
#27 _SocketBase._sendToEventHandler.<anonymous closure> (dart:io-patch:512:20)
#28 _ReceivePortImpl._handleMessage (dart:isolate-patch:40:92)
問題はMogoDartライブラリにあると思いますが、よくわかりません。誰かが私を助けることができますか?