Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ferrum.async submodule for working with promises #162

Open
koraa opened this issue Feb 24, 2021 · 0 comments
Open

ferrum.async submodule for working with promises #162

koraa opened this issue Feb 24, 2021 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed needs-api-design

Comments

@koraa
Copy link
Contributor

koraa commented Feb 24, 2021

We should provide a support module for working with promises.

// Can be imported by path and using destructuring
const { fork } = require('ferrum/async');
const { async: { fork } } = require('ferrum');

// Promise constructor as a free function
const makePromise = builder(Promise);

// Mostly useful as an annotation in code that this starts a new fiber
const fork = (fn) => Promise.resolve(fn(v));

// Fork from a sequence; useful because Promise.all cannot be used as a free function; needs a better name
const parallel = (seq) => Promise.all(iter(seq));

// Iterate over a sequence of promises in the order they resolve (multiple races). Returns async iterator (needs better name)
const race_all = 

const race = (seq) => Promise.race(iter(seq));

// Promise with resolve/reject
class Barrier extends Promise{
  constructor(fn /* maybe null */) {}
  resolve(v) {}
  reject(v) {}
  intoPromise() {}
};

// WaitEvent
const waitEvent = (emitter, eventName) => makePromise((res) => 

class Channel {
  constructor
}

Functions from: https://github.com/adobe-rnd/helix-harmonicabsorber/blob/master/src/asyncio.js

@koraa koraa added the enhancement New feature or request label Feb 24, 2021
@koraa koraa changed the title IO module ferrum.io submodule for working with promises Apr 30, 2021
@koraa koraa changed the title ferrum.io submodule for working with promises ferrum.async submodule for working with promises Apr 30, 2021
@koraa koraa added help wanted Extra attention is needed needs-api-design labels Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed needs-api-design
Projects
None yet
Development

No branches or pull requests

1 participant