diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b7791..a92dae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ Changes to the project are tracked using build numbers behind the version number ## [Unreleased] +## [1.0.0-beta.16+13] - 2024-08-26 + +- Feat: Added `mutex` flag that default to `false` (off) to methods of the `SurrealWasmMutex` class to allow turn on/off the mutex locking mechanism. + ## [1.0.0-beta.16+12] - 2024-08-24 - Feat: Added `SurrealWasmMutex` class to workaround the issue [#87](https://github.com/surrealdb/surrealdb.wasm/issues/87) of the surrealdb.wasm. diff --git a/RELEASE.md b/RELEASE.md index 8ab408c..a1ec91e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1 +1 @@ -- Feat: Added `SurrealWasmMutex` class to workaround the issue [#87](https://github.com/surrealdb/surrealdb.wasm/issues/87) of the surrealdb.wasm. \ No newline at end of file +- Feat: Added `mutex` flag that default to `false` (off) to methods of the `SurrealWasmMutex` class to allow turn on/off the mutex locking mechanism. diff --git a/lib/src/surreal_wasm_mutex.dart b/lib/src/surreal_wasm_mutex.dart index 40401b9..0bc67a4 100644 --- a/lib/src/surreal_wasm_mutex.dart +++ b/lib/src/surreal_wasm_mutex.dart @@ -17,137 +17,234 @@ class SurrealWasmMutex extends Surreal { } @override - Future let(String key, Object value) async { - await _mutex.protect(() async { - return super.let(key, value); - }); + Future let(String key, Object value, {bool mutex = false}) async { + if (!mutex) { + await super.let(key, value); + } else { + await _mutex.protect(() async { + return super.let(key, value); + }); + } } @override - Future unset(String key) async { - await _mutex.protect(() async { - return super.unset(key); - }); + Future unset(String key, {bool mutex = false}) async { + if (!mutex) { + await super.unset(key); + } else { + await _mutex.protect(() async { + return super.unset(key); + }); + } } @override - Future signup(Map credentials) async { - return _mutex.protect(() async { + Future signup( + Map credentials, { + bool mutex = false, + }) async { + if (!mutex) { return super.signup(credentials); - }); + } else { + return _mutex.protect(() async { + return super.signup(credentials); + }); + } } @override - Future signin(Map credentials) async { - return _mutex.protect(() async { + Future signin( + Map credentials, { + bool mutex = false, + }) async { + if (!mutex) { return super.signin(credentials); - }); + } else { + return _mutex.protect(() async { + return super.signin(credentials); + }); + } } @override - Future invalidate() async { - await _mutex.protect(() async { - return super.invalidate(); - }); + Future invalidate({bool mutex = false}) async { + if (!mutex) { + await super.invalidate(); + } else { + await _mutex.protect(() async { + return super.invalidate(); + }); + } } @override - Future authenticate(String token) async { - await _mutex.protect(() async { - return super.authenticate(token); - }); + Future authenticate(String token, {bool mutex = false}) async { + if (!mutex) { + await super.authenticate(token); + } else { + await _mutex.protect(() async { + return super.authenticate(token); + }); + } } @override - Future info() async { - return _mutex.protect(() async { + Future info({bool mutex = false}) async { + if (!mutex) { return super.info(); - }); + } else { + return _mutex.protect(() async { + return super.info(); + }); + } } @override Future patch( String resource, - List> data, - ) async { - return _mutex.protect(() async { + List> data, { + bool mutex = false, + }) async { + if (!mutex) { return super.patch(resource, data); - }); + } else { + return _mutex.protect(() async { + return super.patch(resource, data); + }); + } } @override - Future version() async { - return _mutex.protect(() async { + Future version({bool mutex = false}) async { + if (!mutex) { return super.version(); - }); + } else { + return _mutex.protect(() async { + return super.version(); + }); + } } @override Future connect( String endpoint, { Map options = const {}, + bool mutex = false, }) async { - await _mutex.protect(() async { - return super.connect(endpoint, options: options); - }); + if (!mutex) { + await super.connect(endpoint, options: options); + } else { + await _mutex.protect(() async { + return super.connect(endpoint, options: options); + }); + } } @override - Future close() async { - await _mutex.protect(() async { - return super.close(); - }); + Future close({bool mutex = false}) async { + if (!mutex) { + await super.close(); + } else { + await _mutex.protect(() async { + return super.close(); + }); + } } @override - Future use({String? namespace, String? database}) async { - await _mutex.protect(() async { - return super.use(namespace: namespace, database: database); - }); + Future use({ + String? namespace, + String? database, + bool mutex = false, + }) async { + if (!mutex) { + await super.use(namespace: namespace, database: database); + } else { + await _mutex.protect(() async { + return super.use(namespace: namespace, database: database); + }); + } } @override - Future create(String resource, Object data) async { - return _mutex.protect(() async { + Future create( + String resource, + Object data, { + bool mutex = false, + }) async { + if (!mutex) { return super.create(resource, data); - }); + } else { + return _mutex.protect(() async { + return super.create(resource, data); + }); + } } @override - Future update(String resource, Object data) async { - return _mutex.protect(() async { + Future update( + String resource, + Object data, { + bool mutex = false, + }) async { + if (!mutex) { return super.update(resource, data); - }); + } else { + return _mutex.protect(() async { + return super.update(resource, data); + }); + } } @override - Future merge(String resource, Object data) async { - return _mutex.protect(() async { + Future merge( + String resource, + Object data, { + bool mutex = false, + }) async { + if (!mutex) { return super.merge(resource, data); - }); + } else { + return _mutex.protect(() async { + return super.merge(resource, data); + }); + } } @override - Future select(String resource) async { - return _mutex.protect(() async { + Future select(String resource, {bool mutex = false}) async { + if (!mutex) { return super.select(resource); - }); + } else { + return _mutex.protect(() async { + return super.select(resource); + }); + } } @override Future query( String sql, { Map bindings = const {}, + bool mutex = false, }) async { - return _mutex.protect(() async { + if (!mutex) { return super.query(sql, bindings: bindings); - }); + } else { + return _mutex.protect(() async { + return super.query(sql, bindings: bindings); + }); + } } @override - Future delete(String resource) async { - return _mutex.protect(() async { + Future delete(String resource, {bool mutex = false}) async { + if (!mutex) { return super.delete(resource); - }); + } else { + return _mutex.protect(() async { + return super.delete(resource); + }); + } } }