BlyxDocumentation
Browse chapters
Documentation / Workflow recipes

Petrel · Decide whether a queued request can afford to wait

Admit an immediate charge or report the wait a request can afford.

Decide whether a queued request can afford to wait

Charging a delayed request immediately can remove capacity from unrelated work. Return the wait separately from the updated balance. The bucket has four tokens and needs eight. At two tokens per tick the charge fits the two-tick deadline.

Run the framework with your own input

Install Blyx 0.2.1 and a Rust toolchain with a host linker, then run the versioned project. Each positional argument is a number or a comma-separated numerical vector. The CLI accepts up to 16 entries per vector. The imported module accepts longer inputs.

git clone --depth 1 --branch v0.1.0 https://github.com/Rahulchaube1/blyx-petrel.git
cd blyx-petrel
blyxc native-run project.blyx -- 2 10 2 1 8 2

API and return values

Returns [charge now, balance after immediate decision, feasible by deadline, wait]. Deferred work consumes no tokens until resubmitted. Invalid input returns an empty vector.

ArgumentAccepted input
tokensnonnegative finite number
capacitypositive finite number
ratepositive finite number
elapsednonnegative finite number
costpositive finite number
deadlinenonnegative finite number

Use the libraries independently

The framework vendors the same library source published in these two repositories. Each module has its own package page, input contract and regression suite.

Try the program

Output Ready
Expected output
0
4
1
2
Open in the full playground →

Practice

Change elapsed = 4.0, deadline = 0.0. Predict the result, then run the program.

Hint

Returns [charge now, balance after immediate decision, feasible by deadline, wait]. Deferred work consumes no tokens until resubmitted.

Worked solution

The result vector is [1, 2, 1, 0]. Compare its fields with the return layout in the API section.

Find

    let elapsed = 1.0;

Replace with

    let elapsed = 4.0;

Find

    let deadline = 2.0;

Replace with

    let deadline = 0.0;

Output after the change

1
2
1
0