magickSetProgressMonitor method

Future<void> magickSetProgressMonitor(
  1. MagickProgressMonitor progressMonitor, [
  2. dynamic clientData
])

MagickSetProgressMonitor() sets the wand progress monitor to monitor the progress of an image operation to the specified method.

  • clientData : any user-provided data that will be passed to the progress monitor callback.

Implementation

//TODO: If the progress monitor method returns false, the current operation is
// interrupted.
/// - [clientData] : any user-provided data that will be passed to the
/// progress monitor callback.
Future<void> magickSetProgressMonitor(MagickProgressMonitor progressMonitor,
    [dynamic clientData]) async {
  if (_progressMonitorReceivePort == null) {
    _progressMonitorReceivePort = ReceivePort();
    _progressMonitorReceivePortSendPortPtr =
        _pluginBindings.magickSetProgressMonitorPort(
      _wandPtr.cast(),
      _progressMonitorReceivePort!.sendPort.nativePort,
    );
    _progressMonitorStreamController = StreamController<dynamic>.broadcast();
    _progressMonitorReceivePortStreamSubscription =
        _progressMonitorReceivePort!.listen((dynamic data) {
      if (_progressMonitorStreamController!.hasListener) {
        _progressMonitorStreamController!.add(data);
      }
    });
  }
  await _progressMonitorStreamControllerStreamSubscription
      ?.cancel(); // Cancel previous subscription, if any.
  _progressMonitorStreamControllerStreamSubscription =
      _progressMonitorStreamController!.stream.listen((event) {
    final dynamic data = jsonDecode(event);
    progressMonitor(data['info'], data['offset'], data['size'], clientData);
  });
}