1.0.11 • Published 6 years ago

synchronize-async v1.0.11

Weekly downloads
10
License
BSD-2-Clause
Repository
github
Last release
6 years ago

synchronize-async Build Status

Sometimes, you want you methods to act synchronous. This library helps.

Simple add the synchronize decorator to methods that should be synchronized, like this:

import {synchronize} from "synchronize-async";

class SillyCalculatorExample {
    current = 0;

    @synchronize()
    async add(value) {
        await new Promise(resolve => setTimeout(resolve, 2000));
        this.current += value;
        return this.current;
    }

}

Now this code will yield in the proper result!

import * as assert from "assert";
import {synchronize, join} from "synchronize-async";

const calculator = new SillyCalculatorExample();
calculator.add(5).then(value => {
    // value === 5
    assert.equal(value, 5);
});
calculator.add(5).then(value => {
    // value === 10 (!)
    assert.equal(value, 10);
});

// also, you can get the result of the last promise with the join function
join(calculator).then(value => {
    assert.equal(value, 10);
});
1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago