Skip to content

Consider async wrappers for Push/Pull methods #22

@petrroll

Description

@petrroll

Hi, using your library (awesome btw!) I wrote little wrappers that take the REST functions and turn them to async methods.

I was thinking if you'd be interested in having something similar (more generic and with proper exception propagation, ofc) in the library itself. I was thinking about having one async method per operation e.g.:

class Firebase{
    public Task<(Firebase, DataSnapshot)> PushStateAsync(string str)
    {
        var fbNode = this.Copy(); // (so that we can guarantee there's no callback sharing)
        var taskCompletionSource = new TaskCompletionSource<(Firebase, DataSnapshot)>();

        fbNode.OnPushSuccess += (Firebase node, DataSnapshot pushedKeyInfo) => { taskCompletionSource.SetResult((node, pushedKeyInfo)); }; ;
        fbNode.OnPushFailed += (Firebase fireBase, FirebaseError error) => { taskCompletionSource.SetException(error); };
        fbNode.Push(str);

        return taskCompletionSource.Task;
    }
}

I know it's not the most efficient implementation (a lot of allocations and whatnot) but it's not all that bad either.

I'd be happy to implement it but don't want to work on it in case it wouldn't be merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions