diff --git a/lib/src/isolate_manager.dart b/lib/src/isolate_manager.dart index edcbe6d..4c5fb3c 100644 --- a/lib/src/isolate_manager.dart +++ b/lib/src/isolate_manager.dart @@ -41,6 +41,8 @@ class IsolateManager { QueueStrategy? queueStrategy, this.isDebug = false, }) : isCustomIsolate = false, + // This API will be removed in v6.0.0 when we reach the stable release. + // ignore: deprecated_member_use_from_same_package initialParams = '', queueStrategy = queueStrategy ?? QueueStrategyUnlimited(), _workerName = workerName, @@ -70,6 +72,8 @@ class IsolateManager { IsolateManager.createCustom( IsolateCustomFunction this.isolateFunction, { String? workerName, + // This API will be removed in v6.0.0 when we reach the stable release. + // ignore: deprecated_consistency this.initialParams, this.concurrent = 1, this.converter, @@ -308,6 +312,9 @@ class IsolateManager { final String? _workerName; /// Initial parameters. + @Deprecated( + 'This API will be removed in v6.0.0 when we reach the stable release.', + ) final Object? initialParams; /// Is using your own isolate function. @@ -398,6 +405,8 @@ class IsolateManager { IsolateContactor.createCustom( isolateFunction as IsolateCustomFunction, workerName: workerName, + // This API will be removed in v6.0.0 when we reach the stable release. + // ignore: deprecated_member_use_from_same_package initialParams: initialParams, converter: converter, workerConverter: workerConverter, diff --git a/lib/src/isolate_manager_function.dart b/lib/src/isolate_manager_function.dart index b202ef9..69a2b9a 100644 --- a/lib/src/isolate_manager_function.dart +++ b/lib/src/isolate_manager_function.dart @@ -7,11 +7,20 @@ import 'package:isolate_manager/src/isolate_worker/isolate_worker_web.dart' /// A callback for the [IsolateManagerFunction.customFunction] that will be executed only one time /// before all events. +@Deprecated( + 'Use `IsolateOnInitCallback` instead. This API will be removed in v6.0.0 when we reach the stable release.', +) typedef IsolateOnInitialCallback = FutureOr Function( IsolateManagerController controller, T initialParams, ); +/// A callback for the [IsolateManagerFunction.customFunction] that will be executed only one time +/// before all events. +typedef IsolateOnInitCallback = FutureOr Function( + IsolateManagerController controller, +); + /// A callback for the [IsolateManagerFunction.customFunction] that will be executed only one time /// before all events. typedef IsolateOnDisposeCallback = void Function( @@ -64,7 +73,11 @@ abstract class IsolateManagerFunction { /// A default parameter that used by the package. dynamic params, { required IsolateOnEventCallback onEvent, + @Deprecated( + ' Use `onInit` instead. This API will be removed in v6.0.0 when we reach the stable release.', + ) IsolateOnInitialCallback? onInitial, + IsolateOnInitCallback? onInit, IsolateOnDisposeCallback? onDispose, bool autoHandleException = true, bool autoHandleResult = true, @@ -144,9 +157,17 @@ abstract class IsolateManagerFunction { /// ``` static Future workerFunction( IsolateWorkerFunction function, { + @Deprecated( + 'Use `onInit` instead. This API will be removed in v6.0.0 when we reach the stable release.', + ) FutureOr Function()? onInitial, + IsolateOnInitCallback? onInit, }) { - return isolateWorkerImpl(function, onInitial); + assert( + onInitial == null || onInit == null, + 'Provide either `onInit` or `onInitial`, not both.', + ); + return isolateWorkerImpl(function, onInitial, onInit); } /// Create a custom Worker function. diff --git a/lib/src/isolate_worker/isolate_worker_stub.dart b/lib/src/isolate_worker/isolate_worker_stub.dart index 68aa105..f3f4c18 100644 --- a/lib/src/isolate_worker/isolate_worker_stub.dart +++ b/lib/src/isolate_worker/isolate_worker_stub.dart @@ -8,7 +8,11 @@ import 'package:isolate_manager/src/isolate_manager_function.dart'; /// No-op on `io`. Future isolateWorkerImpl( IsolateWorkerFunction function, + @Deprecated( + 'Use `onInit` instead. This API will be removed in v6.0.0 when we reach the stable release.', + ) FutureOr Function()? onInitial, + IsolateOnInitCallback? onInit, ) { throw UnimplementedError('Use only on the Web platform to create a Worker'); } diff --git a/lib/src/isolate_worker/isolate_worker_web.dart b/lib/src/isolate_worker/isolate_worker_web.dart index 83dcda8..ccbbfdc 100644 --- a/lib/src/isolate_worker/isolate_worker_web.dart +++ b/lib/src/isolate_worker/isolate_worker_web.dart @@ -13,11 +13,16 @@ external DedicatedWorkerGlobalScope get _self; /// Create a worker in your `main`. Future isolateWorkerImpl( IsolateWorkerFunction function, + @Deprecated( + 'Use `onInit` instead. This API will be removed in v6.0.0 when we reach the stable release.', + ) FutureOr Function()? onInitial, + IsolateOnInitCallback? onInit, ) async { final controller = IsolateManagerController(_self); await onInitial?.call(); + await onInit?.call(controller); controller.onIsolateMessage.listen((message) async { try { diff --git a/test/isolate_manager_test.dart b/test/isolate_manager_test.dart index 283d3b4..eced0ee 100644 --- a/test/isolate_manager_test.dart +++ b/test/isolate_manager_test.dart @@ -920,10 +920,7 @@ Future isolateFunction(dynamic params) async { } return 0; }, - onInitial: ( - IsolateManagerController controller, - Object? initialParams, - ) {}, + onInit: (IsolateManagerController controller) {}, onDispose: (IsolateManagerController controller) {}, autoHandleException: false, autoHandleResult: false, @@ -937,10 +934,7 @@ void isolateFunctionWithAutomaticallyHandlers(dynamic params) { onEvent: (IsolateManagerController controller, int message) { return fibonacci(message); }, - onInitial: ( - IsolateManagerController controller, - Object? initialParams, - ) {}, + onInit: (IsolateManagerController controller) {}, onDispose: (IsolateManagerController controller) {}, ); }