@@ -818,69 +818,61 @@ class Query<T> {
818818 return result;
819819 }
820820
821- /// Finds Objects matching the query, streaming them while the query executes.
822- ///
823- /// Note: make sure you evaluate performance in your use case - streams come
824- /// with an overhead so a plain [find()] is usually faster.
825- Stream <T > stream () => _stream1 ();
826-
827821 /// Finds Objects matching the query, streaming them while the query executes.
828822 ///
829823 /// Results are streamed from a worker isolate in batches (the stream still
830824 /// returns objects one by one).
831- ///
832- /// This is typically faster than [stream()] and even [find()] .
833- @experimental
834- Stream <T > streamAsync () => _streamIsolate ();
825+ Stream <T > stream () => _streamIsolate ();
835826
836827 /// Stream items by sending full flatbuffers binary as a message.
837- Stream <T > _stream1 () {
838- initializeDartAPI ();
839- final port = ReceivePort ();
840- final cStream = checkObxPtr (
841- C .dartc_query_find (_cQuery, port.sendPort.nativePort), 'query stream' );
842-
843- var closed = false ;
844- final close = () {
845- if (closed) return ;
846- closed = true ;
847- C .dartc_stream_close (cStream);
848- port.close ();
849- reachabilityFence (this );
850- };
851-
852- try {
853- final controller = StreamController <T >(onCancel: close);
854- port.listen ((dynamic message) {
855- // We expect Uint8List for data and NULL when the query has finished.
856- if (message is Uint8List ) {
857- try {
858- controller.add (
859- _entity.objectFromFB (_store, ByteData .view (message.buffer)));
860- return ;
861- } catch (e) {
862- controller.addError (e);
863- }
864- } else if (message is String ) {
865- controller.addError (
866- ObjectBoxException ('Query stream native exception: $message ' ));
867- } else if (message != null ) {
868- controller.addError (ObjectBoxException (
869- 'Query stream received an invalid message type '
870- '(${message .runtimeType }): $message ' ));
871- }
872- // Close the stream, this will call the onCancel function.
873- // Do not call the onCancel function manually,
874- // if cancel() is called on the Stream subscription right afterwards it
875- // will use the shortcut in the onCancel function and not wait.
876- controller.close (); // done
877- });
878- return controller.stream;
879- } catch (e) {
880- close ();
881- rethrow ;
882- }
883- }
828+ /// Replaced by _streamIsolate which in benchmarks has been faster.
829+ // Stream<T> _stream1() {
830+ // initializeDartAPI();
831+ // final port = ReceivePort();
832+ // final cStream = checkObxPtr(
833+ // C.dartc_query_find(_cQuery, port.sendPort.nativePort), 'query stream');
834+ //
835+ // var closed = false;
836+ // final close = () {
837+ // if (closed) return;
838+ // closed = true;
839+ // C.dartc_stream_close(cStream);
840+ // port.close();
841+ // reachabilityFence(this);
842+ // };
843+ //
844+ // try {
845+ // final controller = StreamController<T>(onCancel: close);
846+ // port.listen((dynamic message) {
847+ // // We expect Uint8List for data and NULL when the query has finished.
848+ // if (message is Uint8List) {
849+ // try {
850+ // controller.add(
851+ // _entity.objectFromFB(_store, ByteData.view(message.buffer)));
852+ // return;
853+ // } catch (e) {
854+ // controller.addError(e);
855+ // }
856+ // } else if (message is String) {
857+ // controller.addError(
858+ // ObjectBoxException('Query stream native exception: $message'));
859+ // } else if (message != null) {
860+ // controller.addError(ObjectBoxException(
861+ // 'Query stream received an invalid message type '
862+ // '(${message.runtimeType}): $message'));
863+ // }
864+ // // Close the stream, this will call the onCancel function.
865+ // // Do not call the onCancel function manually,
866+ // // if cancel() is called on the Stream subscription right afterwards it
867+ // // will use the shortcut in the onCancel function and not wait.
868+ // controller.close(); // done
869+ // });
870+ // return controller.stream;
871+ // } catch (e) {
872+ // close();
873+ // rethrow;
874+ // }
875+ // }
884876
885877 /// Stream items by sending pointers from native code.
886878 /// Interestingly this is slower even though it transfers only pointers...
0 commit comments