# @mybug/wait

> await anything synchronously

Latest version **0.1.4** (published 2019-01-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @mybug/wait
pnpm add @mybug/wait
yarn add @mybug/wait
bun add @mybug/wait
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2019-01-06 |
| First published | 2018-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 1 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | mysyljr |
| Maintainers | mr_jin |
| Keywords | wait, await, awaitor, awaitable, waitable, callback, thunk, mybug, promise, async, sync, es7, debug |

## Links

- npm: https://www.npmjs.com/package/@mybug/wait
- Repository: https://github.com/mysyljr/wait
- Homepage: https://github.com/mysyljr/wait#readme
- Issues: https://github.com/mysyljr/wait/issues
- npm.io page: https://npm.io/package/@mybug/wait

## Dependencies (1)

- [deasync](https://npm.io/package/deasync.md) ^0.1.14

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.1.4 (latest) — 2019-01-06
- 0.1.3 — 2018-12-28
- 0.1.2 — 2018-12-28
- 0.1.1 — 2018-12-28

## README

# [@mybug](https://www.npmjs.com/org/mybug)/wait
await anything synchronously. 

Useful when you want to get the result of async operation inside a synchronous function, while rewriting the 
synchronous 
function 
to be an async one is not possible. (Maybe it's in 3rd party library, or a predefined callback like event handler, etc)

## deprecated
Ownership of this package has been transferred, please use [@superjs/wait](https://www.npmjs
.com/package/@superjs/wait)

## usage
wait(awaitable)

awaitable: a value can be awaited

return the promiseValue of awaitable just like using await, but synchronously. 

## example

```javascript
const wait = require('@mybug/wait')
const su = require('superagent')
let resp = wait(su('https://api.npms.io/v2/search?q=scope:mybug')) //async http request 
console.log(resp.body) // result is printed synchronously
```

## use together with [@mybug/awaitor](https://www.npmjs.com/package/@mybug/awaitor)

wait can resolve an operation which returns a promise, but not an operation which needs a callback.

you can either:
1. wrap the operation to return a promise
2. just call the operation, using @mybug/awaitor as callback, like below  

```javascript
const awaitor = require('@mybug/awaitor')
const wait = require('@mybug/wait')

let cb = awaitor()
foo(1,2,cb) // whenever a callback is needed, just use cb
let result = wait(cb) //result is an array, containing the args cb received
console.log(result) // [3]

function foo(a,b,cb){
  setTimeout(()=>cb(a+b),1000)
}
```

## also useful as debug tool
When being paused on a breakpoint, you can evaluate expressions but no async operations can be evaluated 
immediately.

Using @mybug/wait, you can evaluate an async operation, get the result of it, while still being paused
 on the breakpoint.

Just evaluate `wait(anyAsyncOperation())`, 
you will see the 
async operation gets done and returned.

You don't even have to require @mybug/wait in your code. Just install @mybug/wait as a devDependency. When debugging, 
evaluate `global.wait=process.mainModule.require('@mybug/wait')`. That's all.

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