Coder Social home page Coder Social logo

asdlei99 / c-block Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huxingyi/c-block

0.0 1.0 0.0 12 KB

c-block are extremely lightweight macros designed for eliminate callback hell, inspired by Duff's device and Protothreads. c-block provide sequential flow of control that is similar to the await of c#

C 100.00%

c-block's Introduction

c-block

Overview

c-block are extremely lightweight macros designed for eliminate callback hell, inspired by Duff's device and Protothreads. c-block provide sequential flow of control that is similar to the await of c#.

Callback hell style code:

void stat_cb(uv_fs_t* req) {
  printf("stat result:%d\n", req->result);
  uv_fs_req_cleanup(req);
  free(req);
}

uv_fs_stat(uv_default_loop(), req, "./test.exe", stat_cb);

c-block style code:

int task_clousre(struct task *ctx) {
  c_begin(ctx, task_clousre);
  ctx->u.stat.loop = uv_default_loop();
  ctx->u.stat.path = "./test.exe";
  c_await(&ctx->u.stat, c_fs_stat);
  uv_fs_req_cleanup(&ctx->u.stat.req);
  c_end();
  free(ctx);
  return 0;
}

For full version code, see c-block-uv

Features

  • Low cost, each block use only 12 bytes (on 32bit system)
  • No dependences.
  • Support all platforms.

Warning

  • Do not use local variables. Local variables are not preserved across source lines which containing c-block codes. Put the variables into the context struct.
  • Do not use switch-case between c_begin and c_end. see Duff's device.

Examples

c-block's People

Contributors

huxingyi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.