replaceLast method

T? replaceLast(
  1. T element
)

替换最后一个的元素, 并发射

Implementation

T? replaceLast(T element) {
  if (_subject.isClosed) {
    L.w('IO在close状态下请求发送数据');
    return null;
  }

  final copied = List.of(latest);

  if (latest.isNotEmpty) {
    _subject.add(copied
      ..replaceRange(
        copied.length - 1,
        copied.length,
        [element],
      ));
  }
  return element;
}