Skip to content

Memory leaks with combinator functions #10

Open
@joshdifabio

Description

@joshdifabio

I have uploaded a gist which shows a problem I've encountered recently when using promises and combinators: specifically, using a combinator function (particularly first()/race()/any()) will cause redundant resolver callbacks to remain attached to whichever promises do not 'win' the race to resolve the combined promise. The current Awaitable interface does not provide any mechanism to overcome this issue (e.g. some kind of cancel() or dispose() method). What do others think about this issue?

I don't personally think combinators should implicitly abort 'losing' promises (which is what cancel() sometimes means) but I do think it might be nice to have some kind of dispose() method:

interface Awaitable
{
    public function when(callback $onResolved): Disposable;
}

interface Disposable
{
    /** Inform the awaitable that you no longer care about its result and it can remove your callback **/
    public function dispose();
}

I'm guessing people will be against such a change, but it's come up for me a couple of times so I'm interested to hear people's thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions