calculateDiffInSeparateIsolate<Item> function
Future<List<Operation<Item>>>
calculateDiffInSeparateIsolate<
Item>( - List<Item> oldList,
- List<Item> newList,
- bool areEqual(
- Item a,
- Item b
),
- int getHashCode(
- Item item
),
)
Implementation
Future<List<Operation<Item>>> calculateDiffInSeparateIsolate<Item>(
List<Item> oldList,
List<Item> newList,
bool Function(Item a, Item b) areEqual,
int Function(Item item) getHashCode,
) async {
final receivePort = ReceivePort();
await Isolate.spawn(_calculationInIsolate, receivePort.sendPort);
final port = StreamQueue(receivePort);
final SendPort sendPort = await port.next;
_sendItemList(sendPort, oldList, getHashCode);
_sendItemList(sendPort, newList, getHashCode);
while (!await port.next) {
// Two items' hashCodes match. Let's find out if they're really the same.
final first = oldList[await port.next];
final second = newList[await port.next];
sendPort.send(areEqual(first, second));
}
final operations = await _receiveOperationsList(port, oldList, newList);
receivePort.close();
return operations;
}