https://github.com/awto/mfjs-promise
Wrapper for Promise interface to MFJS
https://github.com/awto/mfjs-promise
Last synced: 3 months ago
JSON representation
Wrapper for Promise interface to MFJS
- Host: GitHub
- URL: https://github.com/awto/mfjs-promise
- Owner: awto
- License: mit
- Created: 2016-05-14T08:49:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-13T18:01:28.000Z (about 10 years ago)
- Last Synced: 2026-04-25T15:35:13.640Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @mfjs/promise
This is a tiny wrapper converting Promise ES compatible API to mfjs interface,
embedding direct asynchronous programming into JavaScript.
## Usage
$ npm install --save-dev @mfjs/compiler
$ npm install --save @mfjs/core @mfjs/promise
$ mfjsc input-file.js -o dist
# or for browser
$ npm install --save-dev browserify @mfjs/compiler
$ npm install --save @mfjs/core @mfjs/promise
$ browserify -t @mfjs/compiler/monadify input.js -o index.js
Here is an example ported from [yield-on-promise](https://www.npmjs.com/package/yield-on-promise),
but can work in browser too.
```javascript
var M = require('@dmjs/core');
var QM = require('@dmjs/promise');
var Q = require('q');
QM.setCtor(Q.Promise);
M.profile('defaultMinimal');
QM.run(function() {
var result = M(addLater(1, 2));
console.log(result); // outputs 3
});
function addLater(a, b) {
var deferred = Q.defer();
process.nextTick(function() {
deferred.resolve(a + b);
});
return deferred.promise;
}
```
## License
Copyright © 2016 Vitaliy Akimov
Distributed under the terms of the [The MIT License (MIT)](LICENSE).