1.2.3 โ€ข Published 2 years ago

@infini-soft/promises v1.2.3

Weekly downloads
-
License
INFINISOFT
Repository
-
Last release
2 years ago

Getting started

๐Ÿค๐Ÿฝ Extended Promises

Extends promises with following features. We use it to help increase UX. Deffered promise combined with async components helps smooth UI transitions and avoid flicker. Timeout increase error and flow control.

โœจ Features

  • No dependency
  • Timeout
  • Deffered
  • Debounce
  • Timeout Debounce simultaneously
  • Helpers
  • Typescript
  • Javascript

๐Ÿ“š Documentation

Get all documentations, examples and execute it directly from our website, the โ˜• kitchen! Come cook software :) https://www.kitchen.infini-soft.com/

๐Ÿ“ฆ Install

$ npm install @infini-soft/promises --save
# or
$ yarn add @infini-soft/promises

๐Ÿ”จ Usage

Timeout

Expected result is to timeout and reject

Timeout is 2000ms
Promise NEVER fullfills (Scenario where a request or Internet is lost)

import React from 'react';
import {
  factoryPromiseFuncNeverResolve,
  promiseTimeout,
} from '@infini-soft/promises';

const test = async () => {
  const start = new Date().getTime();
  try {
    await promiseTimeout({
      request: factoryPromiseFuncNeverResolve,
      timeout: 2000,
    });
  } catch (error) {
    alert(`${error} after ${new Date().getTime() - start} ms`);
  }
};

export default () => (
  <>
    <h3>Timeout 2000 ms</h3>
    <button onClick={() => test()}>Test</button>
  </>
);

Deffered

Expected result is to be completed in ~2000ms.

Deffered is default 2000ms
Promise is resolved in 50ms

import React from 'react';
import {
  factoryPromiseFuncResolveIn,
  promiseDeffered,
} from '@infini-soft/promises';

const test = async () => {
  try {
    const start = new Date().getTime();
    await promiseDeffered({
      request: factoryPromiseFuncResolveIn(50),
      deffered: 2000,
    });
    alert(`Request success deffered after ${new Date().getTime() - start} ms`);
  } catch (error) {
    alert(error);
  }
};

export default () => (
  <>
    <h3>Success 2000 ms</h3>
    <button onClick={() => test()}>Test</button>
  </>
);

Timeout and Deffered

Expected result is to be completed in ~2000ms.

Timeout is default 2000ms
Deffered is default 2000ms
Promise is resolved in 50ms (Timeout is NOT reached)

import React from 'react';
import {
  factoryPromiseFuncResolveIn,
  promiseTimeOutDeffered,
} from '@infini-soft/promises';

const test = async () => {
  try {
    const start = new Date().getTime();
    await promiseTimeOutDeffered({
      request: factoryPromiseFuncResolveIn(50),
      Deffered: 2000,
    });
    alert(`Request success deffered after ${new Date().getTime() - start} ms`);
  } catch (error) {
    alert(error);
  }
};

export default () => (
  <>
    <h3>Success in ~2000 ms</h3>

    <button onClick={() => test()}>Test</button>
  </>
);

๐Ÿง  States / Logic / Sequence Design

Introducing Extended Promises. Problem is the lack of timeout, deffere or debounce in context of front-end to smooth transitions and reduce boiler plate.

Covering all those states together can become cumbersome very quickly. Here is a diagram representing the extended promises.

npm.io npm.io

๐Ÿงช Unit Tested

npm.io


Powered ๐Ÿš€ by Infinisoft Inc. Wanna cook software? come in the kitchen https://www.kitchen.infini-soft.com

1.2.0

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.30

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.27

2 years ago

1.1.25

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago