All C++ work takes place in the cpp
container, i.e.:
From here you can compile, upload and invoke different functions defined in the Faasm C++ repo, or add your own.
If you want to upload C/C++ functions from other repos, you can look at the Faasm HTTP API.
Compiling a C++ functionA simple hello world function is demo/hello
which just returns a hello message.
From the Faasm CLI, you can compile, upload and invoke the hello.cpp
function with:
inv func.compile demo hello inv func.upload demo hello inv func.invoke demo hello
You should then see the response Hello faasm!
.
You can edit the message in the hello.cpp
file, then update and invoke again with:
# Recompile and upload inv func.compile demo hello inv func.upload demo hello # Flush - this is important to remove any cached versions of your function inv func.flush # Invoke again inv func.invoke demo helloWriting functions
Faasm aims to be uninvasive, allowing code to run natively and in a serverless context. This means the simplest Faasm function looks like:
int main(int argc, char* argv[]) { // Do something return 0; }C++ API
Faasm provides a simple C++ wrapper library around the Faasm host interface. Some of the methods in this wrapper are:
faasmGetInput()
- allows functions to retrieve their input data
faasmSetOutput()
- this allows functions to return output data to the caller
faasmChain()
- this allows one function to invoke others
faasmAwaitCall()
- waits for a chained function invocation to finish
faasmReadState()
and writeState()
- allows functions to read/ write key/value state
faasmReadStateOffset()
and faasmWriteStateOffset()
- allows functions to read/ write at specific points in existing state (e.g. updating a subsection of an array)
They are found in the cpp
repo.
“Chaining” is when one function makes a call to another function (which must be owned by the same user). There are two supported methods of chaining, one for invoking totally separate Faasm functions, the other for automatically parallelising functions in the same piece of code (useful for porting legacy applications).
Chaining a functionMultiple functions can be defined in the same file, invoke each other and await results.
Functions can either be chained by passing another function’s name, or by passing a pointer to a function in the same file.
Examples:
Chaining by name demo/chain_named_a
, demo/chain_named_b
, demo/chain_named_c
.
Chaining by function pointer demo/chain
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4