Git Product home page Git Product logo

executor-spike's Introduction

Executor

As the world embraces async/await a increasing number of libraries expose API that are inherently async. This comes with two principal problems.

  1. Async functions imply a runtime but in our software the runtime should be created explicitly and threaded as a dependency through components. Components should probably be tested with a different single threaded runtime than running in production with a multi threaded runtime.

  2. APIs which have async dependencies inherit the color of these functions. But the fact that a function does IO or has an otherwise "effect" should not bleed into the API of it's users. Our APIs should be strictly effect independent.

As an experiment, it would be interesting to see if we can construct a single runtime with a clonable handle. The clonable handle could be passed to other components and bbe a gateway for executing Futures. This gateway would expose a synchronous interface which could be completely mocked out during testing in order to isolate core logic from effects.

Comparables

Libra PeerHandle Libra uses an old version of tokio (0.2.x vs latest 0.3.x) which provides since deprecated clonable Runtime::Handle.

OpenEthereum Runtime Uses an even older version of tokio (v0.1.x vs latest 0.3.x) which uses the depricated TaskExecutor which in a thin wrapper around a thread local global DefaultExecutor struct.

Considerations

  • I didn't want to use any 3rd party libraries here. I tried to make do with the defaults.
  • Obviously this is a trivial construction where the return type is fixed at u32. It might be a bit more challenging to return different structures.
  • Even though internal, the use of Pin<Box<dyn Future<Output=u32> + 'static + Send> makes me personally nervous.

References

executor-spike's People

Contributors

brapse avatar

Watchers

 avatar James Cloos 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.