maxmahem
maxmahem
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
Hmm... when canceling/unsubscribing/disposing of this poll, I wonder if I should wait the task? Just to ensure that the task is completed before I return control.
void PollConsole(IObserver<ConsoleKeyInfo> observer, CancellationToken token)
{
try {
while (!token.IsCancellationRequested) {
while (Console.KeyAvailable) {
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
observer.OnNext(keyInfo);
}
Thread.Sleep(this.pollingInterval);
}
}
catch (Exception error) { observer.OnError(error); }
}
void PollConsole(IObserver<ConsoleKeyInfo> observer, CancellationToken token)
{
try {
while (!token.IsCancellationRequested) {
while (Console.KeyAvailable) {
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
observer.OnNext(keyInfo);
}
Thread.Sleep(this.pollingInterval);
}
}
catch (Exception error) { observer.OnError(error); }
}
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
No description
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
yeah... the interface here sucks. Just leaves polling really, as all the other methods are blocking with no way to cancel.
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
doooh. Tried an await stream solution.. big road block, lol. The stream only sends the next line when you hit enter. Doh. I knew that but forgot.
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
well, my solution at least lets you shove the waiting logic elsewhere. You could also do more sophisticated things with the key stream if you wanted.
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
well the issue is in this case you are somewhat limited by the interface Console exposes.
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
or really...
var cts = new CancellationTokenSource();
var subscription = new AnyKeyObservable().Subscribe(cts.ToCancelObserver());
var cts = new CancellationTokenSource();
var subscription = new AnyKeyObservable().Subscribe(cts.ToCancelObserver());
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
I know my solution looks like a lot, but thats partially because I did it all from scratch. On the consuming end it can just look like:
var cts = new CancellationTokenSource();
var keyPressObservable = new AnyKeyObservable();
var subscription = keyPressObservable.Subscribe(cts.ToCancelObserver());
var cts = new CancellationTokenSource();
var keyPressObservable = new AnyKeyObservable();
var subscription = keyPressObservable.Subscribe(cts.ToCancelObserver());
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
awaiting the input stream is still a decent idea though.
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
I think reactive has some stuff built in that does just this, but I thought I'd try writing it from scratch.
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
and there is an observer that triggers a cancelation when it sees any event
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
the essence is there is an observable that polls the keyboard for an key, and emits an event if any key is pressed
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
okay this was way longer then necessary because I did it withhout reactive.linq but... https://paste.mod.gg/dvfzwhdjpopo/0
45 replies
CC#
Created by honey the codewitch on 12/18/2024 in #help
Looking for a better way to cancel on keypress from the console
give me a sec.
45 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
hah, well if you look at the code it already did some of thosoe.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
anyways in SQL terms the DB would be something like:
CREATE TABLE People (
PersonId INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Age INT
);

CREATE TABLE Friendships (
PersonId INT NOT NULL,
FriendId INT NOT NULL,
PRIMARY KEY (PersonId, FriendId),
FOREIGN KEY (PersonId) REFERENCES People(PersonId) ON DELETE CASCADE,
FOREIGN KEY (FriendId) REFERENCES People(PersonId) ON DELETE CASCADE,
CONSTRAINT CHK_NotSelfFriendship CHECK (PersonId != FriendId)
);
CREATE TABLE People (
PersonId INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Age INT
);

CREATE TABLE Friendships (
PersonId INT NOT NULL,
FriendId INT NOT NULL,
PRIMARY KEY (PersonId, FriendId),
FOREIGN KEY (PersonId) REFERENCES People(PersonId) ON DELETE CASCADE,
FOREIGN KEY (FriendId) REFERENCES People(PersonId) ON DELETE CASCADE,
CONSTRAINT CHK_NotSelfFriendship CHECK (PersonId != FriendId)
);
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
good because I don't know as much about that side of things.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
likewise, removing the id from the Person class, and using an auto-incrementing value instead.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
I don't know how familiar you are with DBs, but the thing with using a hashset of Friendship objects makes more sense if you are used to lookup tables of that sort.
128 replies
CC#
Created by paun on 10/3/2024 in #help
In Memory DATABase troubles
Sorry if I went to far here.
128 replies