先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
127 lines
4.4 KiB
C#
127 lines
4.4 KiB
C#
using System;
|
|
|
|
namespace UniRx
|
|
{
|
|
public static partial class Observable
|
|
{
|
|
public static Func<IObservable<TResult>> FromAsyncPattern<TResult>(Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)
|
|
{
|
|
return () =>
|
|
{
|
|
var subject = new AsyncSubject<TResult>();
|
|
try
|
|
{
|
|
begin(iar =>
|
|
{
|
|
TResult result;
|
|
try
|
|
{
|
|
result = end(iar);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
subject.OnError(exception);
|
|
return;
|
|
}
|
|
subject.OnNext(result);
|
|
subject.OnCompleted();
|
|
}, null);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
return Observable.Throw<TResult>(exception, Scheduler.DefaultSchedulers.AsyncConversions);
|
|
}
|
|
return subject.AsObservable();
|
|
};
|
|
}
|
|
|
|
public static Func<T1, IObservable<TResult>> FromAsyncPattern<T1, TResult>(Func<T1, AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)
|
|
{
|
|
return x =>
|
|
{
|
|
var subject = new AsyncSubject<TResult>();
|
|
try
|
|
{
|
|
begin(x, iar =>
|
|
{
|
|
TResult result;
|
|
try
|
|
{
|
|
result = end(iar);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
subject.OnError(exception);
|
|
return;
|
|
}
|
|
subject.OnNext(result);
|
|
subject.OnCompleted();
|
|
}, null);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
return Observable.Throw<TResult>(exception, Scheduler.DefaultSchedulers.AsyncConversions);
|
|
}
|
|
return subject.AsObservable();
|
|
};
|
|
}
|
|
|
|
public static Func<T1, T2, IObservable<TResult>> FromAsyncPattern<T1, T2, TResult>(Func<T1, T2, AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)
|
|
{
|
|
return (x, y) =>
|
|
{
|
|
var subject = new AsyncSubject<TResult>();
|
|
try
|
|
{
|
|
begin(x, y, iar =>
|
|
{
|
|
TResult result;
|
|
try
|
|
{
|
|
result = end(iar);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
subject.OnError(exception);
|
|
return;
|
|
}
|
|
subject.OnNext(result);
|
|
subject.OnCompleted();
|
|
}, null);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
return Observable.Throw<TResult>(exception, Scheduler.DefaultSchedulers.AsyncConversions);
|
|
}
|
|
return subject.AsObservable();
|
|
};
|
|
}
|
|
|
|
public static Func<IObservable<Unit>> FromAsyncPattern(Func<AsyncCallback, object, IAsyncResult> begin, Action<IAsyncResult> end)
|
|
{
|
|
return FromAsyncPattern(begin, iar =>
|
|
{
|
|
end(iar);
|
|
return Unit.Default;
|
|
});
|
|
}
|
|
|
|
public static Func<T1, IObservable<Unit>> FromAsyncPattern<T1>(Func<T1, AsyncCallback, object, IAsyncResult> begin, Action<IAsyncResult> end)
|
|
{
|
|
return FromAsyncPattern(begin, iar =>
|
|
{
|
|
end(iar);
|
|
return Unit.Default;
|
|
});
|
|
}
|
|
|
|
public static Func<T1, T2, IObservable<Unit>> FromAsyncPattern<T1, T2>(Func<T1, T2, AsyncCallback, object, IAsyncResult> begin, Action<IAsyncResult> end)
|
|
{
|
|
return FromAsyncPattern(begin, iar =>
|
|
{
|
|
end(iar);
|
|
return Unit.Default;
|
|
});
|
|
}
|
|
}
|
|
} |