StreamThreads 1.0.0
See the version list below for details.
dotnet add package StreamThreads --version 1.0.0
NuGet\Install-Package StreamThreads -Version 1.0.0
<PackageReference Include="StreamThreads" Version="1.0.0" />
paket add StreamThreads --version 1.0.0
#r "nuget: StreamThreads, 1.0.0"
// Install StreamThreads as a Cake Addin #addin nuget:?package=StreamThreads&version=1.0.0 // Install StreamThreads as a Cake Tool #tool nuget:?package=StreamThreads&version=1.0.0
StreamThread
Single Threaded Recursive Iterators for Parallel Execution
StreamThreads is a library that allows you to write clean and plain code that can execute processes in parallel, but using only a single thread. It is an alternative to async/await and Task.Run(), but without locks, concurrent collections and synchronization. In some sense, it is more like a game-loop where each object in the scene needs updating every few milliseconds before the screen refreshes. Unfortunately, game-loops often end up with significant amounts of global status variables and case-statements in complex scenes. StreamThread helps by allowing a game-loop to be written as a "multi-threaded" application, where each function is executing independently.
Example:
public IEnumerable<StreamState> StartupState()
{
yield return HandleFault().OnError();
yield return PrintDots(".").Until(() => readyforwork).Background();
yield return GetReady().Await();
yield return WaitForever;
}
This is an example of a function that executes a function (PrintDots) in the background(with the extension .Background()), while executing GetReady() synchroneously (.Await()). If at any point an error happens, whether it is inside the background function or not, the HandleFault (.OnError()) will be called.
private IEnumerable<StreamState> PrintDots(string v)
{
while (true)
{
Console.Write(v);
yield return Sleep(new Random().Next(10, 100));
}
}
Notice how the PrintDots function loops infinitely, and the yield return. This allows the "game-loop" to return and process some of the other running tasks.
StreamThreads is based on Iterators and Extension Methods. As such, yield return is essentially used every time a new function is called - either as a background worker thread, or inline with statements. It is also worth noting that all function should have return type of IEnumerable<StreamState>. This allows for it to be interpreted as an iterator by the compiler.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on StreamThreads:
Package | Downloads |
---|---|
websocket-sharp-Net6.0
websocket-sharp port to net6.0 that fixes StackOverflow |
|
websocket-sharp-Net8.0
websocket-sharp port to net8.0 from |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
2022.8.12.100 | 2,488 | 8/12/2022 | |
2022.8.1.100 | 18,038 | 8/1/2022 | |
2022.7.28.100 | 412 | 7/28/2022 | |
2022.7.27.200 | 446 | 7/27/2022 | |
2022.7.27.100 | 450 | 7/27/2022 | |
2022.7.26.232902 | 438 | 7/26/2022 | |
1.0.0 | 437 | 7/26/2022 |