Expand description
§Job
A Job is the bulk unit of cleaning URLs.
The design of Job is a bit bizarre but well reasoned.
-
Job::lazy_task_configscontains anIteratorofResults ofLazyTaskConfigs. -
The
Resultis because some inputs of gettingLazyTaskConfigs, such as reading from STDIN, may return an error for some but not other inputs. -
LazyTaskConfigs are very cheap to make from common sources of tasks, such as strings, bytes, JSON values, and so on. -
Iterating over a
JobproducesLazyTasks, which is also very cheap. -
LazyTasks can then be sent across threads thenLazyTask::maked intoTasks, which is good because that’s a fairly expensive process. -
Tasks can then beTask::done to return either the cleaned URL or an error.
This design maximizes versatility with minimal performance sacrifices.
-
URL Cleaner’s CLI reads tasks from STDIN, which may at any point start or stop returning errors.
Job::lazy_task_configstaking anIteratorofResults allows handling those errors relatively nicely. -
URL Cleaner Site accepts a list of
LazyTaskConfigs so that only the cost to turn the string into JSON is single threaded. This also allows for individual tasks to be misformed (becauseLazyTaskConfig::JsonValueaccepts any JSON value) without stopping the rest of the tasks from being done. -
URL Cleaner Discord App uses
LazyTaskConfig::Strto use regex captures from a message without allocating each URL into aStringthen (due to the URL spec being inherently complicated) re-allocating thoseStrings intoUrls. This is largely irrelevant because the vast majority of the time between wanting to clean a message and getting the result is in UI and network latency, but it helps in other (currently only theoretical) cases.