createIsolate method
dynamic
createIsolate(
- RequestCreate requestIso
Implementation
createIsolate(RequestCreate requestIso) async {
rcv = ReceivePort();
tokenIsolate = requestIso.token;
sendPort = requestIso.sendPort;
request = ManReques(setting: requestIso.setting, url: '', tokenDownload: 0);
ManSettings setting = requestIso.setting;
speed = Velocity();
reciverData = rcv.listen((m) async {
if (!(m is ManMessagePort)) return;
ManMessagePort rver = m;
if (rver.action == 'add') {
if (startInit && nunRun > 0) {
sendPort.send(
ErrorSendPort(errorObject: 'Se esta descargando otro archivo'),
);
return;
}
downloadSize = 0;
totalSize = 0;
request = rver.download!;
if (request.tokenDownload == tokenDownload) {
sendPort.send(
ErrorSendPort(
errorObject: 'Ya existe una descarga con el mismo token',
),
);
return;
}
mergePart = MergePartDownload(
fileName: request.fileName,
sendPort: sendPort,
);
if (rver.download!.setting == null) {
request.setting = setting;
}
endpart.clear();
mainStatus = ManDownload(
porcent: 0,
sizeDownload: 0,
sizeFinal: 0,
complete: false,
speed: speed.speed,
);
nunRun = 0;
numPart = 0;
if (numDownloadComplete > 0) {
sendInterval.cancel();
}
tokenDownload = rver.download!.tokenDownload;
statusDownload = StatusDownloadSendPort(
tokenDownload: tokenDownload,
status: statusDownloadType.startDownload,
);
startTime = DateTime.now().millisecondsSinceEpoch;
sendPort.send(statusDownload);
download();
} else if (rver.action == 'stop') {
if (startInit) {
endpart.clear();
sendInterval.cancel();
}
startInit = false;
} else if (rver.action == 'forceStart') {
download(forceStart: true);
}
});
sendPort.send(CreateIsolateSendPort(sendPort: rcv.sendPort));
}