Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a C++ subworker library #35

Closed
gavento opened this issue Apr 13, 2018 · 2 comments
Closed

Create a C++ subworker library #35

gavento opened this issue Apr 13, 2018 · 2 comments
Assignees
Labels
enhancement New feature or request governor
Milestone

Comments

@gavento
Copy link
Contributor

gavento commented Apr 13, 2018

Implement a library to make C++ subworker implementation easier. In spirit, this should consist of I/O and Context types, way to declare and register task functions and a simple mainloop function, similarly to #34. Would you sketch the API, @spirali?

@gavento gavento added enhancement New feature or request governor labels Apr 13, 2018
@spirali
Copy link
Collaborator

spirali commented Apr 17, 2018

The is my first skech of API:

#include <rainsw.h>
use namespace rainsw;

// InstanceList = LabeledList<DataInstance>

// This function takes a blob and creates a new one same content + '!' at the end.
Result<InstanceList> example_fn(Context &ctx, const InstanceList &inputs)
{
        if (inputs.size() != 1) {
		return Result::error("Function expects 1 input object");
	}
	DataObject &obj = inputs.get(0);
        if (!obj.is_blob()) {
		return Result::error("1st argument should be blob");
	}

	Vector<byte> data;
	data.assign(obj.get_ptr(), obj.size());
	data.push_back('!');

	InstanceList result;
	result.push_back(DataObject(data));
	return Result<InstanceList>(std::move(result));
}

int main() {
   Subworker subworker;
   subworker.add_fn("example", example_fn);
   subworker.run();
}

@spirali spirali added this to the v0.3 milestone May 16, 2018
@spirali
Copy link
Collaborator

spirali commented May 20, 2018

Basic C++ subworker library implemented in 437dc2b

@spirali spirali closed this as completed May 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request governor
Projects
None yet
Development

No branches or pull requests

2 participants