浏览代码

move multistream to a single file as it is not supported in the original flutter 1.17.5

/main
Xingwei Zhu 3 年前
当前提交
3bb37db4
共有 4 个文件被更改,包括 80 次插入71 次删除
  1. 12
      com.unity.uiwidgets/Runtime/async/stream.cs
  2. 59
      com.unity.uiwidgets/Runtime/async/stream_impl.cs
  3. 77
      com.unity.uiwidgets/Runtime/async/stream_multi.cs
  4. 3
      com.unity.uiwidgets/Runtime/async/stream_multi.cs.meta

12
com.unity.uiwidgets/Runtime/async/stream.cs


() => (_PendingEvents<T>) new _IterablePendingEvents<T>(elements));
}
public static Stream<T> multi(Action<MultiStreamController<T>> onListen, bool isBroadcast = false) {
return new _MultiStream<T>(onListen, isBroadcast);
}
public static Stream<T> periodic(TimeSpan period,
Func<int, T> computation = null) {
Timer timer = default;

_sink.close();
return Future._nullFuture;
}
}
public interface MultiStreamController<T> : IStreamController<T> {
void addSync(T value);
void addErrorSync(object error, string trackStack);
void closeSync();
}
}

59
com.unity.uiwidgets/Runtime/async/stream_impl.cs


return new _DoneStreamSubscription<T>(() => onDone());
}
}
class _MultiStream<T> : Stream<T> {
public override bool isBroadcast {
get {
return _isBroadcast;
}
}
bool _isBroadcast;
/// The callback called for each listen.
public readonly Action<MultiStreamController<T>> _onListen;
public _MultiStream(Action<MultiStreamController<T>> _onListen, bool isBroadcast) {
_isBroadcast = isBroadcast;
this._onListen = _onListen;
}
public override StreamSubscription<T> listen(Action<T> onData, Action<object, string> onError = null,
Action onDone = null, bool cancelOnError = false) {
var controller = new _MultiStreamController<T>();
controller.onListen = () => {
_onListen(controller);
};
return controller._subscribe(
onData, onError, onDone, cancelOnError);
}
}
class _MultiStreamController<T> : _AsyncStreamController<T>, MultiStreamController<T> {
public _MultiStreamController() : base(null, null, null, null)
{
}
public void addSync(T value) {
if (!_mayAddEvent) throw _badEventState();
if (hasListener) _subscription._add(value);
}
public void addErrorSync(object error, string trackStack) {
if (!_mayAddEvent) throw _badEventState();
if (hasListener) {
_subscription._addError(error, trackStack ?? "");
}
}
public void closeSync() {
if (isClosed) return;
if (!_mayAddEvent) throw _badEventState();
_state |= _StreamController<T>._STATE_CLOSED;
if (hasListener) _subscription._close();
}
public override Stream<T> stream {
get {
throw new Exception("Not available");
}
}
}
}

77
com.unity.uiwidgets/Runtime/async/stream_multi.cs


using System;
namespace Unity.UIWidgets.async {
public class StreamMultiUtils<T>
{
public static Stream<T> multi(Action<MultiStreamController<T>> onListen, bool isBroadcast = false) {
return new _MultiStream<T>(onListen, isBroadcast);
}
}
public interface MultiStreamController<T> : IStreamController<T> {
void addSync(T value);
void addErrorSync(object error, string trackStack);
void closeSync();
}
class _MultiStream<T> : Stream<T> {
public override bool isBroadcast {
get {
return _isBroadcast;
}
}
bool _isBroadcast;
/// The callback called for each listen.
public readonly Action<MultiStreamController<T>> _onListen;
public _MultiStream(Action<MultiStreamController<T>> _onListen, bool isBroadcast) {
_isBroadcast = isBroadcast;
this._onListen = _onListen;
}
public override StreamSubscription<T> listen(Action<T> onData, Action<object, string> onError = null,
Action onDone = null, bool cancelOnError = false) {
var controller = new _MultiStreamController<T>();
controller.onListen = () => {
_onListen(controller);
};
return controller._subscribe(
onData, onError, onDone, cancelOnError);
}
}
class _MultiStreamController<T> : _AsyncStreamController<T>, MultiStreamController<T> {
public _MultiStreamController() : base(null, null, null, null)
{
}
public void addSync(T value) {
if (!_mayAddEvent) throw _badEventState();
if (hasListener) _subscription._add(value);
}
public void addErrorSync(object error, string trackStack) {
if (!_mayAddEvent) throw _badEventState();
if (hasListener) {
_subscription._addError(error, trackStack ?? "");
}
}
public void closeSync() {
if (isClosed) return;
if (!_mayAddEvent) throw _badEventState();
_state |= _StreamController<T>._STATE_CLOSED;
if (hasListener) _subscription._close();
}
public override Stream<T> stream {
get {
throw new Exception("Not available");
}
}
}
}

3
com.unity.uiwidgets/Runtime/async/stream_multi.cs.meta


fileFormatVersion: 2
guid: 5bf5bf2fe1c7407db0a476f2bbcd01f4
timeCreated: 1629701152
正在加载...
取消
保存