mirror of https://github.com/AMT-Cheif/drift.git
Improve error handling in LazyDatabase
This commit is contained in:
parent
ab20d69846
commit
6dc198ecca
|
@ -29,11 +29,11 @@ class LazyDatabase extends QueryExecutor {
|
||||||
return _openDelegate!.future;
|
return _openDelegate!.future;
|
||||||
} else {
|
} else {
|
||||||
final delegate = _openDelegate = Completer();
|
final delegate = _openDelegate = Completer();
|
||||||
Future.value(opener()).then((database) {
|
Future.sync(opener).then((database) {
|
||||||
_delegate = database;
|
_delegate = database;
|
||||||
_delegateAvailable = true;
|
_delegateAvailable = true;
|
||||||
delegate.complete();
|
delegate.complete();
|
||||||
});
|
}, onError: delegate.completeError);
|
||||||
return delegate.future;
|
return delegate.future;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,4 +95,12 @@ void main() {
|
||||||
|
|
||||||
verify(inner.close());
|
verify(inner.close());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('throws when opening method throws', () {
|
||||||
|
final exception = Exception('expected');
|
||||||
|
final lazy = LazyDatabase(() => throw exception);
|
||||||
|
final user = _LazyQueryUserForTest();
|
||||||
|
|
||||||
|
expect(lazy.ensureOpen(user), throwsA(exception));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue