Fix filesystem typed mistake

dev-own-engine
marcelb 8 months ago
parent 11e76a4177
commit 052e8df93d
  1. 8
      lib/filesystem.hpp
  2. 44
      test/test.cpp

@ -20,7 +20,7 @@ namespace fs {
*/
template<typename Callback>
void read(string path, Callback&& callback) {
async( [&path, callback] () {
atask( [&path, callback] () {
string content;
try {
string line;
@ -49,7 +49,7 @@ void read(string path, Callback&& callback) {
* Asynchronous file reading
*/
future<string> read(string path) {
return async( [&path] () {
return atask( [&path] () {
string content;
string line;
ifstream file (path);
@ -73,7 +73,7 @@ future<string> read(string path) {
*/
template<typename Callback>
void write(string path, string content, Callback&& callback) {
async( [&path, &content, callback] () {
atask( [&path, &content, callback] () {
try {
ofstream file (path);
if (file.is_open()) {
@ -96,7 +96,7 @@ void write(string path, string content, Callback&& callback) {
* Asynchronous file writing with callback after write complete
*/
future<void> write(string path, string content) {
return async( [&path, &content] () {
return atask( [&path, &content] () {
ofstream file (path);
if (file.is_open()) {
file << content;

@ -3,7 +3,7 @@
#include "../lib/asynco.hpp"
#include "../lib/event.hpp"
#include "../lib/rotor.hpp"
// #include "../lib/filesystem.hpp"
#include "../lib/filesystem.hpp"
#include <iostream>
#include <unistd.h>
@ -11,7 +11,7 @@
using namespace std;
using namespace marcelb::asynco;
using namespace events;
// using namespace asynco;
using namespace asynco;
using namespace this_thread;
void sleep_to (int _time) {
@ -88,17 +88,17 @@ int main () {
// cout << "interval 4: " << rtime_ms() - start << endl;
// }, 400);
interval inter1 ([&]() {
cout << "interval prvi " << rtime_ms() - start << endl;
}, 1000);
// interval inter1 ([&]() {
// cout << "interval prvi " << rtime_ms() - start << endl;
// }, 1000);
interval inter2 ([&]() {
cout << "interval drugi " << rtime_ms() - start << endl;
}, 2000);
// interval inter2 ([&]() {
// cout << "interval drugi " << rtime_ms() - start << endl;
// }, 2000);
interval inter3 ([&]() {
cout << "interval treći " << rtime_ms() - start << endl;
}, 3000);
// interval inter3 ([&]() {
// cout << "interval treći " << rtime_ms() - start << endl;
// }, 3000);
// interval inter4 ([&]() {
// cout << "interval cetvrti " << rtime_ms() - start << endl;
@ -112,13 +112,13 @@ int main () {
// cout << "interval sesti " << rtime_ms() - start << endl;
// }, 3000);
timeout time1 ( [&] () {
cout << "Close interval 1 i 2 " << rtime_ms() - start << endl;
// inter1.clear();
// cout << "inter1.stop " << inter1.stop << endl;
// inter2.clear();
// cout << "inter2.stop " << inter2.stop << endl;
}, 5000);
// timeout time1 ( [&] () {
// cout << "Close interval 1 i 2 " << rtime_ms() - start << endl;
// // inter1.clear();
// // cout << "inter1.stop " << inter1.stop << endl;
// // inter2.clear();
// // cout << "inter2.stop " << inter2.stop << endl;
// }, 5000);
// timeout time2 ([&] () {
@ -127,11 +127,11 @@ int main () {
// time1.clear();
// }, 2000);
// // ------------------------ MAKE FUNCTIONS ASYNCHRONOUS -------------------------
// // // ------------------------ MAKE FUNCTIONS ASYNCHRONOUS -------------------------
/**
* Run an function asyncronic
*/
// /**
// * Run an function asyncronic
// */
// atask( []() {
// sleep_for(2s); // only for simulate log duration function

Loading…
Cancel
Save