ajanuw-completer
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

ajanuw-completer

模拟dart的 Completer

install

λ npm i ajanuw-completer

browser

<script src="./dist/umd/completer.js"></script>
<script>
  const { Completer } = window.Completer;
  let _data = new Completer();
  _data.promise
    .then((v) => {
      console.log(v); // 233
    })
    .catch((er) => {
      console.log(er);
    });

  setTimeout(() => {
    _data.complete(233);
    console.log(_data.isCompleted); // true
  }, 2000);

  setTimeout(() => {
    _data.complete(233); // error
  }, 3000);
</script>

node

import { Completer } from "ajanuw-completer";

let _data: Completer<number> = new Completer<number>();
_data.promise
  .then(v => {
    console.log(v); // 233
  })
  .catch(er => {
    console.log(er);
  });

setTimeout(() => {
  _data.complete(233);
  console.log(_data.isCompleted); // true
}, 2000);

Package Sidebar

Install

npm i ajanuw-completer

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

14.3 kB

Total Files

17

Last publish

Collaborators

  • ajanuw