Divulge HN: Minute GO library for verify async purpose response

111
Divulge HN: Minute GO library for verify async purpose response

codecov

Minute GO library for verify async purpose response.

Present some weird and wonderful performance for conditional test

plug salvage github.com/PxyUp/verifiers

Necessary: all purpose would perhaps be performed if condition are matched (it is some distance mean all minute one routine would perhaps be stopped)

verifiers.All

form Verifier func(ctx context.Context) error

All(fns ...Verifier) error

Formula verifies is all purpose performed without error in given context timeout/slice-off date

Instance success:

v := verifiers.Contemporary(ctx)
startTime := time.Now()
err := v.All(
    func(ctx context.Context) error {
        time.Sleep(time.2nd)
        return nil
    },
    func(ctx context.Context) error {
        time.Sleep(time.2nd * 2)
        return nil
    },
    func(ctx context.Context) error {
        time.Sleep(time.2nd * 3)
        return nil
    },
)
// Because we could perhaps well peaceful wait most trendy purpose
convey.Upright(t, time.Now().Sub(startTime) >= time.2nd*3)

Instance error:

v := verifiers.Contemporary(ctx)
startTime := time.Now()
err := v.All(
    func(ctx context.Context) error {
        time.Sleep(time.2nd)
        return errors.Contemporary("")
    },
    func(ctx context.Context) error {
        time.Sleep(time.2nd * 2)
        return nil
    },
    func(ctx context.Context) error {
        time.Sleep(time.2nd * 3)
        return nil
    },
)
// Because we can throw error after first return it
convey.Upright(t, time.Now().Sub(startTime)  time.Second*2)

verifiers.OneOf

type Verifier func(ctx context.Context) error

OneOf(fns ...Verifier) error

Method verifies is at least one function finished without error in given context timeout/deadline

=time.Second*1)
assert.True(t, time.Now().Sub(startTime)
v := verifiers.New(ctx)
startTime := time.Now()
err := v.OneOf(
    func(ctx context.Context) error {
        time.Sleep(time.Second)
        return nil
    },
    func(ctx context.Context) error {
        time.Sleep(time.Second * 2)
        return errors.New("")
    },
    func(ctx context.Context) error {
        time.Sleep(time.Second * 3)
        return nil
    },
)
// Because we should wait second function
assert.True(t, time.Now().Sub(startTime) >= time.2nd*1)
convey.Upright(t, time.Now().Sub(startTime)  time.2nd*3)

verifiers.AtLeast

form Verifier func(ctx context.Context) error

AtLeast(fns ...Verifier) error

Formula verifies is on the least equipped amount of capabilities would perhaps be performed without error in given context timeout/slice-off date

time.2nd*1)
convey.Tru

Read More

Charlie Layers
WRITTEN BY

Charlie Layers

Fill your life with experiences so you always have a great story to tell

you're currently offline