@@ -3,7 +3,6 @@ import 'dart:html';
33import 'dart:js_interop' ;
44import 'dart:js_interop_unsafe' ;
55
6- import 'package:async/async.dart' ;
76import 'package:sqlite3_web/sqlite3_web.dart' ;
87
98final sqlite3WasmUri = Uri .parse ('sqlite3.wasm' );
@@ -13,17 +12,27 @@ const databaseName = 'database';
1312WebSqlite ? webSqlite;
1413
1514Database ? database;
16- StreamQueue < void > ? updates;
15+ int updates = 0 ;
1716
1817void main () {
1918 _addCallbackForWebDriver ('detectImplementations' , _detectImplementations);
2019 _addCallbackForWebDriver ('close' , (arg) async {
2120 await database? .dispose ();
2221 return null ;
2322 });
24- _addCallbackForWebDriver ('wait_for_update' , _waitForUpdate);
23+ _addCallbackForWebDriver ('get_updates' , (arg) async {
24+ return updates.toJS;
25+ });
2526 _addCallbackForWebDriver ('open' , _open);
2627 _addCallbackForWebDriver ('exec' , _exec);
28+ _addCallbackForWebDriver ('test_second' , (arg) async {
29+ final endpoint = await database! .additionalConnection ();
30+ final second = await WebSqlite .connectToPort (endpoint);
31+
32+ await second.execute ('SELECT 1' );
33+ await second.dispose ();
34+ return true .toJS;
35+ });
2736
2837 document.getElementById ('selfcheck' )? .onClick.listen ((event) async {
2938 print ('starting' );
@@ -79,11 +88,6 @@ Future<JSString> _detectImplementations(String? _) async {
7988 }).toJS;
8089}
8190
82- Future <JSAny ?> _waitForUpdate (String ? _) async {
83- await updates! .next;
84- return null ;
85- }
86-
8791Future <JSAny ?> _open (String ? implementationName) async {
8892 final sqlite = initializeSqlite ();
8993 Database db;
@@ -103,7 +107,7 @@ Future<JSAny?> _open(String? implementationName) async {
103107 // Make sure it works!
104108 await db.select ('SELECT database_host()' );
105109
106- updates = StreamQueue (db. updates);
110+ db. updates. listen ((_) => updates++ );
107111 database = db;
108112 return returnValue? .toJS;
109113}
0 commit comments