TIL: 19th July 2023

context in Go may cross the process boundaries§

Context is implemented in Go through the standard library context package to pass the deadlines, cancellations and arbitrary data between the programming interfaces, as well as goroutines and threads.

As the documentation states:

Package context defines the Context type, which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes.

It's also designed to cross the process boundaries and, while this isn't something the standard library implements, gRPC for one does exactly this in order to communicate metadata between the client and the server. That's cool!

futures in Rust are state machines§

Rust has a built-in async/await language feature that helps write asynchronous code. At the same time it doesn't provide a runtime, letting the ecosystem come up with various approaches using the same building blocks such as std::future::Future trait.

A popular runtime built by the Rust community is tokio, which has a great in-depth demonstration of this asynchronous runtime model.

The value returned by an async function is really a lazy future, which is scheduled for execution when an .await is called on it. The executor is the responsible for polling the future's state by calling the Future::poll function implemented for the trait until the execution is complete. Completion is defined by future returning std::task::Poll::Ready with the computation result. Otherwise future returns std::task::Poll::Pending value.

Moreover, future is supposed to tell the executor when it's ready to do some work if it's still Pending by calling the std::task::Waker::wake method. This way the executor is only scheduling the execution to the medium (e.g. a thread) when the task is ready to be executed (e.g. receiving a TCP packet), but the future is entirely responsible for progressing its own state.

This means future is a state machine.

most cats have the same blood group§

Now for something completely different. Today I've been organising a blood transfusion for one of our old cats suffering from the kidney disease that has progressed into a severe anaemia. One of the complexities from living in the countryside amid the war in your country is that you're going to do a lot on your own. Getting feline blood for a transfusion is one of those things.

Fortunately, there are several animal blood banks in Kyiv that is reachable by car in an hour. Unfortunately, this material is rather rare in general since blood donations are complicated for cats and pet owners don't usually do that (or even know about it). And then, it's not like your pet can consent for a donation with clear understanding of the risks, which can be morally ambiguous.

We were lucky since our cat has the blood group A, which today I learned is what between 72% and 86% of the cats possess depending on their origin. This is due to the pair of genes being responsible for a cat's blood group with the gene for group A being dominant. At the same time, some pedigree breeds have a higher percentage of group B occurrences due to artificial selection from specific gene pools.

Such a strong prevalence of group A in the general population means possessing group B would make finding the right transfusion material even more difficult.