# blocking-style

> Allows JavaScript synchronous coding style

Latest version **1.0.0** (published 2017-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install blocking-style
pnpm add blocking-style
yarn add blocking-style
bun add blocking-style
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-08-11 |
| First published | 2017-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | v8.2.1 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | djulien |
| Maintainers | djulien |

## Links

- npm: https://www.npmjs.com/package/blocking-style
- Repository: https://github.com/djulien/blocking-style
- Homepage: https://github.com/djulien/blocking-style#readme
- Issues: https://github.com/djulien/blocking-style/issues
- npm.io page: https://npm.io/package/blocking-style

## Dependencies (1)

- [keypress](https://npm.io/package/keypress.md) ^0.2.1

## Recent versions

- 1.0.0 (latest) — 2017-08-11

## README

# blocking-style
Allows synchronous coding style in JavaScript

# Installation
`npm install blocking-style --save`

# Example usage
```javascript
require('blocking-style');
...
const {onexit, blocking, wait, prompt} = require('blocking-style');

onexit(function()
{
    console.log("this function called when main finishes");
});


//main function:
blocking(function*()
{
    console.log("start");

    var response = yield prompt("Waits here until something entered ...");
    console.log("you entered '%s'", response.replace(/\n/, "\\n"));

    for (var i = 0; i < 10; ++i)
    {
        console.log("wait");
        yield wait(1); //pause 1 sec
    }
    console.log("done");
});
```

Main function will wait synchronously for events such as keyboard entry or timer.  

Internally the code is still asynchronous, but a generator function can be used to allow the code to be structured with a synchronous, blocking code style like in other languages.
This can make the code easier to read, rather than using a bunch of callback functions.

See test/test.js for an example.

# License
MIT

---
_Source: https://npm.io/package/blocking-style · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
