Giter Site home page Giter Site logo

circuitbreaker's Introduction

Build Status

CircuitBreaker

use CircuitBreaker;

CircuitBreaker.config:  # set new defaults
    :2retries,
    :3failures,
    :1000timeout,
    :10000reset-time
;

sub cbreaker is circuit-breaker{:default<ERROR>} {
    sleep rand * 2;
    $data
}

my Promise @proms;
my $counter = 0;

loop {
    @proms .= grep: Planned;
    for @proms.elems ..^ 5 {
        @proms.push: cbreaker($counter++).then: {printf "\r% 10s => %d", .result, @proms.elems}
    }
    await Promise.anyof: @proms
}
use CircuitBreaker;

CircuitBreaker.config:  # set new defaults
    :2retries,
    :3failures,
    :1000timeout,
    :10000reset-time
;

my &cbreaker := circuit-breaker :default<ERROR>, -> $data {
    sleep rand * 2;
    $data
}

my Promise @proms;
my $counter = 0;

loop {
    @proms .= grep: Planned;
    for @proms.elems ..^ 5 {
        @proms.push: cbreaker($counter++).then: {printf "\r% 10s => %d", .result, @proms.elems}
    }
    await Promise.anyof: @proms
}
use CircuitBreaker;

my &cbreaker := circuit-breaker :default<ERROR>, -> $data {
    sleep rand * 2;
    $data
}

&cbreaker.config:   # configure de defined circuitbreaker
    :2retries,
    :3failures,
    :1000timeout,
    :10000reset-time
;
use CircuitBreaker;

my &my-circuit-breaker := CircuitBreaker.new:   # create a new object
    :2retries,
    :3failures,
    :1000timeout,
    :10000reset-time,
    :exec(-> *@pars, :$of {
        "do something"
    })
;

my $response = await my-circuit-breaker "my", "list". :of<parameters>;

Testing:

use Test;
use CircuitBreaker;
my $*CircuitBreakerMock = CircuitBreaker.mock-router;

my &cbreaker := circuit-breaker :name<test>, -> $name {
    "do something with $name"
}

is await(cbreaker "my name"), "do something with my name", "It shouldn't timeout";

$*CircuitBreakerMock.test.should-timeout(:once);

dies-ok { await cbreaker "my name" }, "It should timeout";

circuitbreaker's People

Contributors

fco avatar

Watchers

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