Fix filesystem typed mistake

dev-own-engine
marcelb 6 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> template<typename Callback>
void read(string path, Callback&& callback) { void read(string path, Callback&& callback) {
async( [&path, callback] () { atask( [&path, callback] () {
string content; string content;
try { try {
string line; string line;
@ -49,7 +49,7 @@ void read(string path, Callback&& callback) {
* Asynchronous file reading * Asynchronous file reading
*/ */
future<string> read(string path) { future<string> read(string path) {
return async( [&path] () { return atask( [&path] () {
string content; string content;
string line; string line;
ifstream file (path); ifstream file (path);
@ -73,7 +73,7 @@ future<string> read(string path) {
*/ */
template<typename Callback> template<typename Callback>
void write(string path, string content, Callback&& callback) { void write(string path, string content, Callback&& callback) {
async( [&path, &content, callback] () { atask( [&path, &content, callback] () {
try { try {
ofstream file (path); ofstream file (path);
if (file.is_open()) { if (file.is_open()) {
@ -96,7 +96,7 @@ void write(string path, string content, Callback&& callback) {
* Asynchronous file writing with callback after write complete * Asynchronous file writing with callback after write complete
*/ */
future<void> write(string path, string content) { future<void> write(string path, string content) {
return async( [&path, &content] () { return atask( [&path, &content] () {
ofstream file (path); ofstream file (path);
if (file.is_open()) { if (file.is_open()) {
file << content; file << content;

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

Loading…
Cancel
Save